Positive random number

G

Golden California Girls

pete said:
Johannes said:
Keith said:
On Tue, 18 Dec 2007 00:43:10 -0800 (PST), deepak
Can someone give the standard function which can create positive
integer value in C?
Other's have talked about "rand()",
but I don't see anything in your
post that requires it.
[...]

The subject was "Positive random number". That information should
have been in the body of the original post.

Th return value of rand isn't guaranteed to be positive.

The rand() function computes a sequence of pseudo-random integers in the
range of 0 to RAND_MAX (as defined by the header file <stdlib.h>).
 
P

Philip Potter

Johannes said:
They are not obscure. Consider the work of Peano
(http://en.wikipedia.org/wiki/Giuseppe_Peano) which in his older works
state that the positive Integers start at 1, while at a later release
(Peano.G.: Formulaire de mathématiques 5 Bde. Turin, Bocca 1895-1908) he
states they start at zero.

The sets he refers to are often called the "natural numbers", and there
*is* difference in the mathematical community as to whether they should
be defined to start at 0 or 1. But nobody ever asks the question "Is
zero natural?" because it's all a matter of definition, and so long as
you're clear which definition you're using, or the result is the same
regardless, it doesn't matter.
It is *not* something that "almost all mathematicians" agree about, it
is primarily a question of usefulness. Both variants are common, it even
depends which university you're attending. Dogmatism are stupid, there
are good reasons why zero should be considered a positive integer and
there are also good reasons why it shouldn't. It's important to base
your decision on reason, not on "that's what I think everybody is doing".

Really? At some point you just have to say "that's what I think
everybody is doing" because all you're doing is agreeing on a common
language. Which side of the road do you drive on? The same side everyone
else does. There is no reason it should be left or right - it just is.

I've never met anyone who considered zero to be positive. Therefore, I
do not consider zero to be positive. If I want to say "positive or zero"
I'd generally say "nonnegative".
Then again - in a trueley mathematic sense - almost all mathematicians
consider zero to be nonpositive. Almost all of them agree that zero is a
positive number, too. This is because "almost" in a mathematic sense
means "except for a finite number of exceptions" :)

Only when the "all" is an infinite set. Which the set of mathemeticians
isn't.

Phil
 
T

Tor Rustad

Johannes Bauer wrote:

[...]
Then again - in a trueley mathematic sense - almost all mathematicians
consider zero to be nonpositive. Almost all of them agree that zero is a
positive number, too. This is because "almost" in a mathematic sense
means "except for a finite number of exceptions" :)

#define is_zero_positive 0

T wrapper_positive(T number)
{
return is_zero_positive ? number : number + 1;
}

<gd&r>
 
J

Johannes Bauer

Philip said:
Really? At some point you just have to say "that's what I think
everybody is doing" because all you're doing is agreeing on a common
language. Which side of the road do you drive on? The same side everyone
else does. There is no reason it should be left or right - it just is.

Well at exactly *that* problem (zero positive or not) there's *no*
"common opinion". Impressively demonstrated by the fact that even Peano
himself (Peano Axioms! A *great* mathematician in the field of integer
arithmetic) had a reason to change his opinion.

Which fits your analogy nicely, as people in Great Britain drive on the
left side of the road and people in the US on the right side. So there
is obviously no dogmatic "correct way", but you have to ask: where
should I drive? In which environment is it *useful*? I will drive on the
left/right side because I an $WHEREEVER.
I've never met anyone who considered zero to be positive.

You just did.
Therefore, I
do not consider zero to be positive. If I want to say "positive or zero"
I'd generally say "nonnegative".

I've never met a person speaking Aymara, therefore I consider nobody is
speaking Aymara. Everyone who does is obviosly speaking the wrong language.

It's not something to argue about, actually: it's a definition (clear by
the meaning of the word "axiom", actually). It's just frustrating to
meet people over and over again who have never heared of any discussion
about this topic and therefore believe their opinion is the only/best
one. Reminds me of all these stupid US Americans who believe Europe is a
country and who become angry when you tell them that Mexico is a part of
America.

Greetings,
Johannes
 
S

santosh

Johannes Bauer wrote:

<snip discussion about whether zero should be considered
positive or not>

The status of zero in mathematics seems to be similar to that of the
photon in physics. The "correct" definition in a particular case is the
definition that yields good results!
 
R

Richard Heathfield

santosh said:
Johannes Bauer wrote:

<snip discussion about whether zero should be considered
positive or not>

The status of zero in mathematics seems to be similar to that of the
photon in physics. The "correct" definition in a particular case is the
definition that yields good results!

The important thing is not what mathematicians think about 0, but what C
programmers think about 0. And it can be shown from the Standard that 0 is
neither positive nor negative.

See, for example, 3.3.5 (Multiplicative operators - and I'm quoting from
C89 here), which says (of division / and modulo %) that "if the value of
the second operand is zero, the behavior is undefined", before going on to
define the behaviour for positive and negative operands. If zero is either
positive or negative, a contradiction arises. Therefore, it cannot be
either.
 
J

jameskuyper

Johannes said:
James Kuyper schrieb: ...

They are not obscure. Consider the work of Peano
(http://en.wikipedia.org/wiki/Giuseppe_Peano) which in his older works
state that the positive Integers start at 1, while at a later release
(Peano.G.: Formulaire de mathématiques 5 Bde. Turin, Bocca 1895-1908) he
states they start at zero.

I think that counts as obscure, as far a non-mathematicians are
concerned.
It is *not* something that "almost all mathematicians" agree about, it
is primarily a question of usefulness. Both variants are common, it even

Again, I don't believe that both are common outside of mathematics
departments. Among users of mathematics, rather than producers, the
idea that 0 might count as positive is pretty much unheard of.
depends which university you're attending. Dogmatism are stupid, there
are good reasons why zero should be considered a positive integer and
there are also good reasons why it shouldn't. It's important to base
your decision on reason, not on "that's what I think everybody is doing".

My reason says that if the definition of positive is changed to ">=0",
I will still need a term for ">0", and it will have to be a new term
distinguishable from "positive". If you want to have a new name for
what I've always heard referred to as "non-negative", why not give it
a name that has no prior contradictory associations? I personally have
never use "positive" in a context where the new proposed definition
would be an acceptable replacement, and I don't think I've ever seen
it used in such a context either.
Then again - in a trueley mathematic sense - almost all mathematicians
consider zero to be nonpositive. Almost all of them agree that zero is a
positive number, too. This is because "almost" in a mathematic sense
means "except for a finite number of exceptions" :)

I'm familiar with this meaning for "almost all", and I think you've
misapplied it. I don't remember the precise definition, but I believe
that the entire set has to be infinitely bigger than the set of
exceptions. For instance, a function that is 0 for all real values,
except that it is 1 for all integers, then that function is 0 "almost
everywhere". I don't believe that the set of mathematicians is
infinitely larger than the subset who hold those opinions.
 
W

Walter Roberson

I'm familiar with this meaning for "almost all", and I think you've
misapplied it. I don't remember the precise definition, but I believe
that the entire set has to be infinitely bigger than the set of
exceptions. For instance, a function that is 0 for all real values,
except that it is 1 for all integers, then that function is 0 "almost
everywhere". I don't believe that the set of mathematicians is
infinitely larger than the subset who hold those opinions.


"Almost all non-negative even numbers less than 1 google are non-prime."

Is "1 google" infinite? No. Is the statement true? I think nearly
everyone (who knows what prime numbers are) would agree that it is
true.

"1 google" is close enough to "infinity" for -practical- purposes as to
make no difference, but I -believe- that if you change "google"
to "million" or even "thousand" that very close to the same number
of people would continue to agree that the modified statement is true.

I believe if you reduced the number down to 20 that the disagreement
rate would be very nearly the same; even at 11 I don't think the
disagreement rate would be significantly higher.

Now, if you reduced the limit to 3 then I could imagine people
getting bothered about the wording, since "almost all" in that case
would be empty. At 4 or 5 then the "almost all" sample size would
be the same as the size of the alternative and people might still
get flustered about the wording. But I believe that one single
exception out of a relatively small set would still broadly be agreed
as the rest being "almost all". I suspect that the psychology of
"almost all" gets more muddy when there are multiple exceptions.
 
K

Keith Thompson

"Almost all non-negative even numbers less than 1 google are non-prime."
[...]

Quibble: the number is "googol", not "google". Google "googol" to
verify.
 
U

user923005

Hi,

Can someone give the standard function which can create positive
integer value in C?

int the_standard_function(void)
{
return 1;
}

It's always positive, but the randomness has something to be desired.
So QOI could use some help.
 
R

Richard Heathfield

user923005 said:
int the_standard_function(void)
{
return 1;
}

It's always positive, but the randomness has something to be desired.
So QOI could use some help.

This is better, but still needs work.

unsigned long the_standard_function_mk2(unsigned long seed)
{
return seed ? seed : ++seed;
}
 
J

jameskuyper

Walter said:
"Almost all non-negative even numbers less than 1 google are non-prime."

Is "1 google" infinite? No. Is the statement true? I think nearly
everyone (who knows what prime numbers are) would agree that it is
true.

Johannes was, very explicitly, invoking the definition within advanced
mathematics of that term, not the ordinary definition. And the
mathematical definition of "almost all" does not cover your example.
If I remember correctly, it requires definition of a measure that can
be applied to the base set, and that measure has to be greater than 0;
while the measure of the exception set has to be exactly 0. For
instance, the appropriate measure for my example would one which
defines the measure of a set of real numbers x such that a<=x && x<=b
as being b-a. Using that measure, the measure of the set of integers
is 0, since that set is a union of a countable infinity of subsets of
measure 0. On the other hand, the measure of the set of real numbers
is infinite.

For your example, since you're describing only integers, the most
appropriate measure would appear to be the count of the number of
elements in each set. When you apply that measure to your exception
set, it gives a non-zero value.

The commonsense definition of "almost all" cannot cover both of the
uses that Johannes made of the term, because at least one of the two
describes a majority of mathematicians (though he didn't identify
which one that was.
 
J

Johannes Bauer

Richard said:
The important thing is not what mathematicians think about 0, but what C
programmers think about 0. And it can be shown from the Standard that 0 is
neither positive nor negative.

This is a very good point. So in terms of C, we have an exact answer.

Greetings,
Johannes
 
J

Johannes Bauer

I personally have
never use "positive" in a context where the new proposed definition
would be an acceptable replacement, and I don't think I've ever seen
it used in such a context either.

Yes, your reasoning sounds well. It's just that your earlier posting
gave me a wrong impression on what you thought, I guess. And I've been
exposed to far too many people who proclaimed "absolute thruths" without
judging their usefulness.
I'm familiar with this meaning for "almost all", and I think you've
misapplied it. I don't remember the precise definition, but I believe
that the entire set has to be infinitely bigger than the set of
exceptions.

Yes, I believe you are right here, I forgot about this constraint.

And, as Richard pointed out: In terms of C, there is only one answer :)

Greetings,
Johannes
 
P

pete

Johannes said:
Reminds me of all these stupid US Americans who believe Europe is a
country and who become angry when you tell them that Mexico is a part
of America.

If you don't have a problem referring to
Los Estados Unidos Mexicanos as just "Mexico",
then you shouldn't have too much of a problem referring to
The United States Of America as just "America".
 
R

Richard Tobin

Reminds me of all these stupid US Americans who [...] become angry
when you tell them that Mexico is a part of America.

Have you actually met any such people? What are the circumstances that
result in you telling them that?

-- Richard
 
J

jacob navia

pete said:
If you don't have a problem referring to
Los Estados Unidos Mexicanos as just "Mexico",
then you shouldn't have too much of a problem referring to
The United States Of America as just "America".

Hey...

"America" is a CONTINENT that goes from Alaska to Tierra del Fuego
in Chile and Argentina.

U.S. citizens are a small part of that continent.

Canada is a part of North America, together with Mexico.

But they are so taken for granted, the poor Canadians.

And Mexicans, well, forget them...

And the rest of the continent?

They don't count anyway.

Europe?

Ah yes, The capital of that country is London isn't it?
 
P

pete

jacob said:
Hey...

"America" is a CONTINENT that goes from Alaska to Tierra del Fuego
in Chile and Argentina.

"America", as a geographic entity,
is the same type of thing that "Eurasia" is.

North America is a continent.
South America is a continent.

The definitions for the word, typically name them all.
http://dictionary.reference.com/search?q=continent

While both continents together may be referred to as "America",
we usually call them "The Americas".

http://dictionary.reference.com/search?q=The+Americas

The reason that The United States Of America is called what it is,
as though there were no other states in the Western hemisphere,
is because at the time,
there were no other states in the Western hemisphere.
There were only tribes, tribal nations
and colonies of foreign nations.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top