By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,838 Members | 2,222 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,838 IT Pros & Developers. It's quick & easy.

Positive random number

P: n/a
Hi,

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

Thanks,
Deepak
Dec 18 '07 #1
Share this Question
Share on Google+
63 Replies


P: n/a
deepak said:
Hi,

Can someone give the standard function which can create positive
integer value in C?
What does your textbook say about the generation of random numbers?

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Dec 18 '07 #2

P: n/a
deepak wrote:
Hi,

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

Thanks,
Deepak
Look-up rand.

Dec 18 '07 #3

P: n/a
On Dec 18, 4:27 am, santosh <santosh....@gmail.comwrote:
deepak wrote:
Hi,
Can someone give the standard function which can create positive
integer value in C?
Thanks,
Deepak

Look-up rand.
You may want to man for rand series entirely; e.g. you may want to use
srand, and seed it with something like your system time to generate
random sequences, etc.

:D
Dec 18 '07 #4

P: n/a
deepak wrote:
Hi,

Can someone give the standard function which can create positive
integer value in C?
There is no standard C function that creates numbers out of nothing.

If you are rather looking for a pseudo-random generator, see the C FAQ.

--
Tor <bw****@wvtqvm.vw | tr i-za-h a-z>
Dec 18 '07 #5

P: n/a
On Tue, 18 Dec 2007 00:43:10 -0800 (PST), deepak
<de*********@gmail.comwrote in comp.lang.c:
Hi,

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. Here's a function guaranteed to meet the
requirement you asked for in the body of your message:

int create_positive_integer_value_in_C(void)
{
return 42;
}

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Dec 19 '07 #6

P: n/a
Jack Klein <ja*******@spamcop.netwrites:
On Tue, 18 Dec 2007 00:43:10 -0800 (PST), deepak
<de*********@gmail.comwrote in comp.lang.c:
>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.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Dec 19 '07 #7

P: n/a
On Tue, 18 Dec 2007 20:30:18 -0600, Jack Klein <ja*******@spamcop.net>
wrote:
>On Tue, 18 Dec 2007 00:43:10 -0800 (PST), deepak
<de*********@gmail.comwrote in comp.lang.c:
>Hi,

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. Here's a function guaranteed to meet the
requirement you asked for in the body of your message:

int create_positive_integer_value_in_C(void)
{
return 42;
}
Definitely *not* guaranteed.

In C99, section 5.2.4.1 Translation limits:

"The implementation shall be able to translate and execute at least
one program that contains at least one instance of every one of the
following limits:

....

31 significant initial characters in an external identifier..."

The identifier "create_positive_integer_value_in_C" is an external
identifier with 34 characters, and thus exceeds the minimum number of
characters *guaranteed* to be accepted by the standard. In C90, the
minimum was a paltry six characters.

Now, an identifier such as "create_positive_int_value_in_C" (30
characters) is acceptable in C99, but not necessarily in C90, though
arguably it is acceptable in most--if not all--C90 compilers in the
real world (for that matter, so is
"create_positive_integer_value_in_C" :^)

--
jay
Dec 19 '07 #8

P: n/a
jaysome wrote:
On Tue, 18 Dec 2007 20:30:18 -0600, Jack Klein <ja*******@spamcop.net>
wrote:
>>On Tue, 18 Dec 2007 00:43:10 -0800 (PST), deepak
<de*********@gmail.comwrote in comp.lang.c:
>>Hi,

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. Here's a function guaranteed to meet the
requirement you asked for in the body of your message:

int create_positive_integer_value_in_C(void)
{
return 42;
}

Definitely *not* guaranteed.

In C99, section 5.2.4.1 Translation limits:

"The implementation shall be able to translate and execute at least
one program that contains at least one instance of every one of the
following limits:

...

31 significant initial characters in an external identifier..."

The identifier "create_positive_integer_value_in_C" is an external
identifier with 34 characters, and thus exceeds the minimum number of
characters *guaranteed* to be accepted by the standard. In C90, the
minimum was a paltry six characters.
What part of "31 significant initial characters" did you not understand.
Jack's function name will only cause problems if he happened to have
defined another identifier with the same sequence of 31 initial
characters.

Dec 19 '07 #9

P: n/a

"santosh" <sa*********@gmail.comschrieb im Newsbeitrag
news:fk**********@registered.motzarella.org...
jaysome wrote:
>On Tue, 18 Dec 2007 20:30:18 -0600, Jack Klein <ja*******@spamcop.net>
wrote:
>>>On Tue, 18 Dec 2007 00:43:10 -0800 (PST), deepak
<de*********@gmail.comwrote in comp.lang.c:

Hi,

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. Here's a function guaranteed to meet the
requirement you asked for in the body of your message:

int create_positive_integer_value_in_C(void)
{
return 42;
}

Definitely *not* guaranteed.

In C99, section 5.2.4.1 Translation limits:

"The implementation shall be able to translate and execute at least
one program that contains at least one instance of every one of the
following limits:

...

31 significant initial characters in an external identifier..."

The identifier "create_positive_integer_value_in_C" is an external
identifier with 34 characters, and thus exceeds the minimum number of
characters *guaranteed* to be accepted by the standard. In C90, the
minimum was a paltry six characters.

What part of "31 significant initial characters" did you not understand.
Jack's function name will only cause problems if he happened to have
defined another identifier with the same sequence of 31 initial
characters.
What part of "Definitely *not* guaranteed" didn't you understand? 8-))

Bye, Jojo
Dec 19 '07 #10

P: n/a
Keith Thompson schrieb:
Jack Klein <ja*******@spamcop.netwrites:
>On Tue, 18 Dec 2007 00:43:10 -0800 (PST), deepak
<de*********@gmail.comwrote in comp.lang.c:
>>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.
http://xkcd.org/221/

:-))

Greetings,
Johannes

--
"Viele der Theorien der Mathematiker sind falsch und klar
Gotteslästerlich. Ich vermute, dass diese falschen Theorien genau
deshalb so geliebt werden." -- Prophet und Visionär Hans Joss aka
HJP in de.sci.mathematik <47**********************@news.sunrise.ch>
Dec 19 '07 #11

P: n/a
Johannes Bauer wrote:
>
Keith Thompson schrieb:
Jack Klein <ja*******@spamcop.netwrites:
On Tue, 18 Dec 2007 00:43:10 -0800 (PST), deepak
<de*********@gmail.comwrote in comp.lang.c:
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.

--
pete
Dec 19 '07 #12

P: n/a
pete said:
Johannes Bauer wrote:
>>
Keith Thompson schrieb:
Jack Klein <ja*******@spamcop.netwrites:
On Tue, 18 Dec 2007 00:43:10 -0800 (PST), deepak
<de*********@gmail.comwrote in comp.lang.c:
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.
Nor is it guaranteed to be random.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Dec 19 '07 #13

P: n/a
pete wrote:
The return value of rand isn't guaranteed to be positive.
What does "positive" mean? Is x positive if and only if x 0?
Does that mean that 0 is neither positive nor negative?

For the record, the rand function computes a sequence of
pseudo-random integers in the range 0 to RAND_MAX.
Dec 19 '07 #14

P: n/a
Spoon wrote:
pete wrote:
>The return value of rand isn't guaranteed to be positive.

What does "positive" mean? Is x positive if and only if x 0?
Does that mean that 0 is neither positive nor negative?
Correct.
Dec 19 '07 #15

P: n/a
Spoon said:
pete wrote:
>The return value of rand isn't guaranteed to be positive.

What does "positive" mean?
Greater than zero.
Is x positive if and only if x 0?
Yes.
Does that mean that 0 is neither positive nor negative?
Yes.
For the record, the rand function computes a sequence of
pseudo-random integers in the range 0 to RAND_MAX.
Yes.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Dec 19 '07 #16

P: n/a
Richard Heathfield schrieb:
>>The return value of rand isn't guaranteed to be positive.
What does "positive" mean?

Greater than zero.
>Is x positive if and only if x 0?

Yes.
>Does that mean that 0 is neither positive nor negative?

Yes.
The question if 0 is positive or not is one which has long been debated
my mathematicians around the world - and still is. Many are of the
opinion that it is useful to define it as positive, just as it is useful
to define 0^0 = 1 (although this is not as clear as it might seem).

The point is: It's a question a definition. Your answer is much too
dogmatic.

Greetings,
Johannes

--
"Viele der Theorien der Mathematiker sind falsch und klar
Gotteslästerlich. Ich vermute, dass diese falschen Theorien genau
deshalb so geliebt werden." -- Prophet und Visionär Hans Joss aka
HJP in de.sci.mathematik <47**********************@news.sunrise.ch>
Dec 19 '07 #17

P: n/a
Johannes Bauer wrote:
Richard Heathfield schrieb:
>>>The return value of rand isn't guaranteed to be positive.
What does "positive" mean?
Greater than zero.
>>Is x positive if and only if x 0?
Yes.
>>Does that mean that 0 is neither positive nor negative?
Yes.

The question if 0 is positive or not is one which has long been debated
my mathematicians around the world - and still is. Many are of the
opinion that it is useful to define it as positive, just as it is useful
to define 0^0 = 1 (although this is not as clear as it might seem).

The point is: It's a question a definition. Your answer is much too
dogmatic.
There might be obscure discussions among mathematicians in which such a
definition is used, but I believe that in almost all contexts, the
overwhelming majority of the mathematically literate population consider
0 to be neither positive nor negative. I don't think it's excessively
dogmatic to insist on interpreting it that way in this context.

Dec 19 '07 #18

P: n/a
James Kuyper schrieb:
>The point is: It's a question a definition. Your answer is much too
dogmatic.

There might be obscure discussions among mathematicians in which such a
definition is used, but I believe that in almost all contexts, the
overwhelming majority of the mathematically literate population consider
0 to be neither positive nor negative. I don't think it's excessively
dogmatic to insist on interpreting it that way in this context.
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.

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".

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" :-)

Greetings,
Johannes

--
"Viele der Theorien der Mathematiker sind falsch und klar
Gotteslästerlich. Ich vermute, dass diese falschen Theorien genau
deshalb so geliebt werden." -- Prophet und Visionär Hans Joss aka
HJP in de.sci.mathematik <47**********************@news.sunrise.ch>
Dec 19 '07 #19

P: n/a
pete wrote:
Johannes Bauer wrote:
>Keith Thompson schrieb:
>>Jack Klein <ja*******@spamcop.netwrites:
On Tue, 18 Dec 2007 00:43:10 -0800 (PST), deepak
<de*********@gmail.comwrote in comp.lang.c:
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>).

Dec 19 '07 #20

P: n/a
Johannes Bauer wrote:
James Kuyper schrieb:
>>The point is: It's a question a definition. Your answer is much too
dogmatic.
There might be obscure discussions among mathematicians in which such a
definition is used, but I believe that in almost all contexts, the
overwhelming majority of the mathematically literate population consider
0 to be neither positive nor negative. I don't think it's excessively
dogmatic to insist on interpreting it that way in this context.

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
Dec 19 '07 #21

P: n/a
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>

--
Tor <bw****@wvtqvm.vw | tr i-za-h a-z>
Dec 19 '07 #22

P: n/a
Philip Potter schrieb:
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

--
"Viele der Theorien der Mathematiker sind falsch und klar
Gotteslästerlich. Ich vermute, dass diese falschen Theorien genau
deshalb so geliebt werden." -- Prophet und Visionär Hans Joss aka
HJP in de.sci.mathematik <47**********************@news.sunrise.ch>
Dec 19 '07 #23

P: n/a
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!

Dec 19 '07 #24

P: n/a
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.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Dec 19 '07 #25

P: n/a
Johannes Bauer wrote:
James Kuyper schrieb:
...
There might be obscure discussions among mathematicians in which such a
definition is used, but I believe that in almost all contexts, the
overwhelming majority of the mathematically literate population consider
0 to be neither positive nor negative. I don't think it's excessively
dogmatic to insist on interpreting it that way in this context.

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 mathmatiques 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.
Dec 19 '07 #26

P: n/a
In article <eb**********************************@n20g2000hsh. googlegroups.com>,
<ja*********@verizon.netwrote:
>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.
--
We regret to announce that sub-millibarn resolution bio-hyperdimensional
plasmatic space polyimaging has been delayed until the release
of Windows Vista SP2.
Dec 19 '07 #27

P: n/a
ro******@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
"Almost all non-negative even numbers less than 1 google are non-prime."
s/google/googol/
--
Ben Pfaff
http://benpfaff.org
Dec 19 '07 #28

P: n/a
In article <87************@blp.benpfaff.org>,
Ben Pfaff <bl*@cs.stanford.eduwrote:
>ro******@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
>"Almost all non-negative even numbers less than 1 google are non-prime."
>s/google/googol/
Dang. Good thing this isn't school and I don't have to write out
"googol" one googol times!
--
So you found your solution
What will be your last contribution?
-- Supertramp (Fool's Overture)
Dec 19 '07 #29

P: n/a
ro******@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
[...]
"Almost all non-negative even numbers less than 1 google are non-prime."
[...]

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

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Dec 19 '07 #30

P: n/a
On Dec 18, 12:43 am, deepak <deepakpj...@gmail.comwrote:
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.
Dec 19 '07 #31

P: n/a
user923005 said:
On Dec 18, 12:43 am, deepak <deepakpj...@gmail.comwrote:
>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.
This is better, but still needs work.

unsigned long the_standard_function_mk2(unsigned long seed)
{
return seed ? seed : ++seed;
}
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Dec 19 '07 #32

P: n/a


Walter Roberson wrote:
In article <eb**********************************@n20g2000hsh. googlegroups.com>,
<ja*********@verizon.netwrote:
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.
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.
Dec 19 '07 #33

P: n/a
Richard Heathfield schrieb:
>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.
This is a very good point. So in terms of C, we have an exact answer.

Greetings,
Johannes

--
"Viele der Theorien der Mathematiker sind falsch und klar
Gotteslästerlich. Ich vermute, dass diese falschen Theorien genau
deshalb so geliebt werden." -- Prophet und Visionär Hans Joss aka
HJP in de.sci.mathematik <47**********************@news.sunrise.ch>
Dec 19 '07 #34

P: n/a
ja*********@verizon.net schrieb:
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.
>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.
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

--
"Viele der Theorien der Mathematiker sind falsch und klar
Gotteslästerlich. Ich vermute, dass diese falschen Theorien genau
deshalb so geliebt werden." -- Prophet und Visionär Hans Joss aka
HJP in de.sci.mathematik <47**********************@news.sunrise.ch>
Dec 19 '07 #35

P: n/a
Johannes Bauer wrote:
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".

--
pete
Dec 19 '07 #36

P: n/a
pete wrote:
Johannes Bauer wrote:
>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".
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?
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Dec 19 '07 #37

P: n/a
pete schrieb:
Johannes Bauer wrote:
>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".
America is a continent.
United States of America are a country.
Mexico is a country.

Continent America != Country America

Big difference.

Greetings,
Johannes

--
"Viele der Theorien der Mathematiker sind falsch und klar
Gotteslästerlich. Ich vermute, dass diese falschen Theorien genau
deshalb so geliebt werden." -- Prophet und Visionär Hans Joss aka
HJP in de.sci.mathematik <47**********************@news.sunrise.ch>
Dec 20 '07 #38

P: n/a
jacob navia schrieb:
Europe?

Ah yes, The capital of that country is London isn't it?
No. It's Paris, where they eat fogs and the Leaning Tower of Pisa is
located!

Greetings,
Johannes

--
"Viele der Theorien der Mathematiker sind falsch und klar
Gotteslästerlich. Ich vermute, dass diese falschen Theorien genau
deshalb so geliebt werden." -- Prophet und Visionär Hans Joss aka
HJP in de.sci.mathematik <47**********************@news.sunrise.ch>
Dec 20 '07 #39

P: n/a
Walter Roberson wrote:
In article <87************@blp.benpfaff.org>,
Ben Pfaff <bl*@cs.stanford.eduwrote:
>ro******@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
>>"Almost all non-negative even numbers less than 1 google are non-prime."
>s/google/googol/

Dang. Good thing this isn't school and I don't have to write out
"googol" one googol times!
No, you have to arrange electrons to spell it out one googolplex times!

Dec 20 '07 #40

P: n/a
Ben Pfaff wrote:
ro******@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
>"Almost all non-negative even numbers less than 1 google are non-prime."

s/google/googol/
Why this disregard for the venerable googolplex?

--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee.
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Dec 20 '07 #41

P: n/a
jacob navia wrote:
>
.... snip ...
>
Europe?

Ah yes, The capital of that country is London isn't it?
True. Since 1814 (or is it 1815?)

--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee.
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Dec 20 '07 #42

P: n/a
Tor Rustad wrote:
deepak wrote:
>Can someone give the standard function which can create positive
integer value in C?

There is no standard C function that creates numbers out of nothing.
However, the sequence "i = N;" is fairly safe, as long as N
represents a sequence of numeric digits (not including the '-'
sign) which represents a value <= INT_MAX. This even has the
elegant characteristic of allowing you to pick your own integer
value (within broad limits).

Another sophisticated sequence (which is not always possible) is:

if (i < 0) i = -i;

HTH

--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee.
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Dec 20 '07 #43

P: n/a
Richard Bos wrote:
....
The USA will just have to get used to being part of a greater world. I
Actually, no it doesn't. The USA is large enough and powerful enough to
get away with considering itself as separate from the rest of the world,
and that is precisely how most USA citizens feel about it. I'm not
advocating this, just pointing it out.

Dec 20 '07 #44

P: n/a
Johannes Bauer wrote:
Philip Potter schrieb:
>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.
Individual mathematicians often differ from orthodoxy. But the "zero
nonpositive" crowd still far outnumber the rest.
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.
And everywhere I have been, 0 is nonpositive.
>I've never met anyone who considered zero to be positive.

You just did.
Do you consider it to be intrinsic to the number or just a useful
definition?
>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.
Not the same thing at all. It's not in my interests to even consider
learning a word of Aymara, but if people want to speak it then I don't
care, so long as they don't try and speak it with me, and if they do
they should expect not to be understood.
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.
Who said I'd never heard discussion on this topic before?

0 is not positive unless stated otherwise. It doesn't have to be this
way, and may in fact change over time [1] but currently it is.

Why get so angry?

Phil

[1] I might have this wrong, but I believe 1 was once considered prime.
Back then it was definitely prime, and these days it is definitely not.
Dec 20 '07 #45

P: n/a
James Kuyper wrote:
Richard Bos wrote:
...
>The USA will just have to get used to being part of a greater world.
I

Actually, no it doesn't. The USA is large enough and powerful enough
to get away with considering itself as separate from the rest of the
world, and that is precisely how most USA citizens feel about it. I'm
not advocating this, just pointing it out.
But the more powerful it becomes, the more it seems to feel the need to
link itself into everyone else' affairs. :-)

Dec 20 '07 #46

P: n/a
santosh wrote:
James Kuyper wrote:
>Richard Bos wrote:
...
>>The USA will just have to get used to being part of a greater world.
I
Actually, no it doesn't. The USA is large enough and powerful enough
to get away with considering itself as separate from the rest of the
world, and that is precisely how most USA citizens feel about it. I'm
not advocating this, just pointing it out.

But the more powerful it becomes, the more it seems to feel the need to
link itself into everyone else' affairs. :-)
Of course; every powerful country does this; it's not peculiar to the USA.
Dec 20 '07 #47

P: n/a
In article <fk**********@aioe.orgPhilip Potter <pg*@doc.ic.ac.ukwrites:
Johannes Bauer wrote:
....
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.

And everywhere I have been, 0 is nonpositive.
Apparently you have never been in France, French speaking Belgium or
French speaking Switzerland (and probably quite a few other places with
strong influence from French mathematics).
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Dec 20 '07 #48

P: n/a
Dik T. Winter wrote:
In article <fk**********@aioe.orgPhilip Potter <pg*@doc.ic.ac.ukwrites:
Johannes Bauer wrote:
...
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.
>
And everywhere I have been, 0 is nonpositive.

Apparently you have never been in France, French speaking Belgium or
French speaking Switzerland (and probably quite a few other places with
strong influence from French mathematics).
Not to mention the number of cases where machine instructions follow
your plan. The first machine I learned on, 30 years ago, designed in
USA, had 2's complement integer and float, and considered 0 as positive.
Dec 20 '07 #49

P: n/a
On Thu, 20 Dec 2007 01:14:12 +0100, Johannes Bauer
<df***********@gmx.dewrote:
>pete schrieb:
>Johannes Bauer wrote:
>>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".

America is a continent.
Well, yes and no. Some people classify North America and South
America as a single continent. However, geologically speaking,
they are two separate continents on separate plates that are
connected by a (geologically) recent land bridge. The existence
of a single continent called America is a by no means universal
linguistic convention

[snip]

Dec 20 '07 #50

63 Replies

This discussion thread is closed

Replies have been disabled for this discussion.