Hello,
We try to generate a random number between 0 and 1.
Does anyone know how?
Thanks!
Hello,
We try to generate a random number between 0 and 1.
Does anyone know how?
Thanks!
Yes.
Edit: Salem pointed this out recently in another thread:
http://www.catb.org/~esr/faqs/smart-...ons.html#prune
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Mainframe assembler programmer by trade. C coder when I can.
Thanks Dino, but it doesn't specify how to make the number in the range 0 to 1.
Matsp, If anyone knows how to generate a random number between 0 and 1 please help us (is this an English forum?)
Do some math!!
1) Figure out what RAND_MAX is.
2) cast the returned value as a double
3) divide #2 by #1 above
Mainframe assembler programmer by trade. C coder when I can.
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
More generally, I suggest that you read Prelude's article on using rand().
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
The typical solution for this is to use C and C++'s remainder operator to force the range down to whatever is desired. For example, to shrink the range into [0..N), one might do this:Code:int r = rand() % N;
>I'm impressed!!
I get "it's" and "its" right most of the time too. How's that for impressive?
My best code is written with the delete key.
Wow.
Mainframe assembler programmer by trade. C coder when I can.