Rand function 
Author Message
 Rand function

   What value range can I expect returned from the rand function?

0 ... RAND_MAX
--
(proud to be, by popular acclamation, the biggest {*filter*} in c.l.c)

Please: do not email me copies of your posts to comp.lang.c
        do not ask me C questions via email; post them instead



Sun, 22 Apr 2001 03:00:00 GMT  
 Rand function

Quote:

> What value range can I expect returned from the rand function?

[0 ... RAND_MAX]

--




Sun, 22 Apr 2001 03:00:00 GMT  
 Rand function

Quote:

>What value range can I expect returned from the rand function?

0 to RAND_MAX. RAND_MAX is defined in <stdlib.h> and is at
least 32767.

--
Craig

Manchester, NH
*plonk* right back at ya!  -- "Country Boy"



Mon, 23 Apr 2001 03:00:00 GMT  
 Rand function
"What's a C book" puzzled and puzzled:
Quote:
>What value range can I expect returned from the rand function?

From zero to RAND_MAX.
HTH

[If you are going to ask what RAND_MAX is, why not ask your compiler?
Compilers are the ones who know such things.  Now, there is a certain guarantee
in the ANSI/ISO C Standard that it is *at least* a certain magic value.  But
the real value is a secret that your compiler will reveal iff you ask in the
right way and include the proper headers.  What are the proper headers?  You
may have a C book handy to tell you.  Actually, it's not plural.  But I thought
I would make it plural so that you would know there are more than one.  You

get back an answer.  In fact, by the time you have finished reading this
message, you could have looked up the answer in your trusty C book.  If it
really *is* a C book, that is.  Not just something pretending to be one.]

--
C-FAQ ftp sites: ftp://ftp.eskimo.com ftp://rtfm.mit.edu
Hypertext C-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-FAQ Book: ISBN 0-201-84519-9.
Want Software?  Algorithms?  Pubs? http://www.infoseek.com



Mon, 23 Apr 2001 03:00:00 GMT  
 Rand function

Quote:


> >What value range can I expect returned from the rand function?

> 0 to RAND_MAX. RAND_MAX is defined in <stdlib.h> and is at
> least 32767.

The portable way to get a random value between 0 and X is

(rand())%(X+1)

Matthew

--
                        Elen Sila Lumenn' Omentielvo
Matthew Vernon, Steward of the Cambridge Tolkien Society
Selwyn College Computer support
http://pick.sel.cam.ac.uk http://www.cam.ac.uk/CambUniv/Societies/tolkien/



Mon, 23 Apr 2001 03:00:00 GMT  
 Rand function

Quote:

> What value range can I expect returned from the rand function?


Others have already recommended RAND_MAX. I thought it worth
mentioning the many good tips about random numbers that can
be found in the comp.lang.c FAQ list. When you're quite new
to dealing with random numbers you will probably apreciate them
a lot. The FAQ answers these questions:
   13.15:  I need a random number generator.
   13.16:  How can I get random integers in a certain range?
   13.17:  Each time I run my program, I get the same sequence of
numbers
           back from rand().
   13.18:  I need a random true/false value, so I'm just taking rand() %
2,
           but it's alternating 0, 1, 0, 1, 0...
   13.20:  How can I generate random numbers with a normal or Gaussian
           distribution?

You can get the FAQ at http://www.eskimo.com/~scs/C-faq/top.html or
at ftp://rtfm.mit.edu/pub/usenet/comp.lang.c/C-FAQ-list and it gets
posted to this newsgroup and to news.answers regularly (at the
beginning of each month).

Stephan
(initiator of the campaign against grumpiness in c.l.c)



Mon, 23 Apr 2001 03:00:00 GMT  
 Rand function

Quote:



> > >What value range can I expect returned from the rand function?

> > 0 to RAND_MAX. RAND_MAX is defined in <stdlib.h> and is at
> > least 32767.

> The portable way to get a random value between 0 and X is

> (rand())%(X+1)

You have just outed yourself as not having read the FAQ :-)
(... or having forgotten most of it)

Because the FAQ carefully explains that using '%' tends to give you
poor quality random numbers. Please look up:
   13.16:  How can I get random integers in a certain range?

You'll get an explanation and some sample code to use instead.

You can get the FAQ at http://www.eskimo.com/~scs/C-faq/top.html or
at ftp://rtfm.mit.edu/pub/usenet/comp.lang.c/C-FAQ-list and it gets
posted to this newsgroup and to news.answers regularly (at the
beginning of each month).

Stephan
(initiator of the campaign against grumpiness in c.l.c)



Mon, 23 Apr 2001 03:00:00 GMT  
 Rand function
Groovy hepcat Matthew Vernon was jivin' on 05 Nov 1998 07:16:17 +0000
in comp.lang.c.
Re: Rand function's a cool scene! Dig it!

Quote:
>> >What value range can I expect returned from the rand function?
>> 0 to RAND_MAX. RAND_MAX is defined in <stdlib.h> and is at
>> least 32767.
>The portable way to get a random value between 0 and X is
>(rand())%(X+1)

  Yes, but what does that have to do with the price of mullet? The
question was about the range of possible values returned by rand(),
not how to get a value from rand() within a certain range.
--

----- Dig the EVEN NEWER, MORE IMPROVED news sig!! -----

-------------- Shaggy was here! ---------------
    http://aardvark.apana.org.au/~phaywood/
============= Ain't I'm a dawg!! ==============



Fri, 27 Apr 2001 03:00:00 GMT  
 Rand function

Quote:
> Groovy hepcat Matthew Vernon was jivin' on 05 Nov 1998 07:16:17 +0000
> in comp.lang.c.
> Re: Rand function's a cool scene! Dig it!

> >> >What value range can I expect returned from the rand function?
> >> 0 to RAND_MAX. RAND_MAX is defined in <stdlib.h> and is at
> >> least 32767.
> >The portable way to get a random value between 0 and X is
> >(rand())%(X+1)

>   Yes, but what does that have to do with the price of mullet? The
> question was about the range of possible values returned by rand(),
> not how to get a value from rand() within a certain range.

Yes, but I was assuming that the most likely use of this information was to get
a random number within a certain range.

You are right that it has nothing to do with the price of mullet tho ;p

Matthew

--
                        Elen Sila Lumenn' Omentielvo
Matthew Vernon, Steward of the Cambridge Tolkien Society
Selwyn College Computer support
http://pick.sel.cam.ac.uk http://www.cam.ac.uk/CambUniv/Societies/tolkien/



Fri, 27 Apr 2001 03:00:00 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. rand() function

2. is rand() function really random

3. Rand-function?

4. rand function

5. RAND ( ) FUNCTION PROBLEM

6. read FAQ, still need a better rand() function!!

7. rand function problem

8. HELP WITH RAND FUNCTION ******* P L E A S E *********

9. HELP WITH RAND FUNCTION ******* P L E A S E **

10. rand() function

11. USING THE RAND FUNCTION

12. rand function syntax

 

 
Powered by phpBB® Forum Software