473,911 Members | 6,170 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Positive random number

Hi,

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

Thanks,
Deepak
Dec 18 '07
63 5725
Keith Thompson schrieb:
Jack Klein <ja*******@spam cop.netwrites:
>On Tue, 18 Dec 2007 00:43:10 -0800 (PST), deepak
<de*********@g mail.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ästerli ch. Ich vermute, dass diese falschen Theorien genau
deshalb so geliebt werden." -- Prophet und Visionär Hans Joss aka
HJP in de.sci.mathemat ik <47************ **********@news .sunrise.ch>
Dec 19 '07 #11
Johannes Bauer wrote:
>
Keith Thompson schrieb:
Jack Klein <ja*******@spam cop.netwrites:
On Tue, 18 Dec 2007 00:43:10 -0800 (PST), deepak
<de*********@gm ail.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
pete said:
Johannes Bauer wrote:
>>
Keith Thompson schrieb:
Jack Klein <ja*******@spam cop.netwrites:
On Tue, 18 Dec 2007 00:43:10 -0800 (PST), deepak
<de*********@g mail.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
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
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
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
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ästerli ch. Ich vermute, dass diese falschen Theorien genau
deshalb so geliebt werden." -- Prophet und Visionär Hans Joss aka
HJP in de.sci.mathemat ik <47************ **********@news .sunrise.ch>
Dec 19 '07 #17
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
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ästerli ch. Ich vermute, dass diese falschen Theorien genau
deshalb so geliebt werden." -- Prophet und Visionär Hans Joss aka
HJP in de.sci.mathemat ik <47************ **********@news .sunrise.ch>
Dec 19 '07 #19
pete wrote:
Johannes Bauer wrote:
>Keith Thompson schrieb:
>>Jack Klein <ja*******@spam cop.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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2516
by: Virus | last post by:
Ok well what I am trying to do is have 1.) the background color to change randomly with 5 different colors.(change on page load) 2,) 10 different quotes randomly fadeing in and out in random spots on the webpage. with a delay timer on them, so they keep changing as the page is open. Not random each time the page is loaded. If anyone can help it would be greatly appreaciated, I have tried many of
10
5996
by: Johnny Snead | last post by:
Hey guys, Need help with this random sort algorithm private void cmdQuestion_Click(object sender, System.EventArgs e) { Random rnd = new Random(); //initialize rnd to new random object System.Random iRnd = new System.Random(); string theNum = iRnd.Next(0,8).ToString(); lblAnswer.Text = iRnd.Next(0,8).ToString();
4
10612
by: fatimahtaher | last post by:
Hi, I am supposed to create a program that generates a random number and then asks the user to guess the number (1-100). The program tells the user if he guessed too high or too low. If he guessed right, it asks the user is he/she wants to play again. If the answer is yes, it generates a random number and asks the user to guess the number again. The user can exit if he enters 0. I have created the following code so far but it does not work....
13
2825
by: Peter Oliphant | last post by:
I would like to be able to create a random number generator that produces evenly distributed random numbers up to given number. For example, I would like to pick a random number less than 100000, or between 0 and 99999 (inclusive). Further, the I want the range to be a variable. Concretely, I would like to create the following method: unsigned long Random( unsigned long num )
0
10037
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10921
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9727
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7250
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5939
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6142
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4776
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4337
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3360
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.