Hi, I'm wondering how do I generate random numbers in decimals?
Meaning between 0-1.
Any ideas? rand() returns from the minimum of 1.
This is a discussion on rand() in decimals. within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm wondering how do I generate random numbers in decimals? Meaning between 0-1. Any ideas? rand() returns from the ...
Hi, I'm wondering how do I generate random numbers in decimals?
Meaning between 0-1.
Any ideas? rand() returns from the minimum of 1.
Read Prelude's article on Using rand(), in particular about creating a uniform deviate.
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
Thanks for the link, my mind must've slipped as this could also be done.
Code:float k = (rand()%10); k = k/10;
>float k = (rand()%10);
>k = k/10;
Apparently you didn't read the entire article. :P
My best code is written with the delete key.
I've always done it like so:
Code:float frand(int chop, int perk = 10) { return (float(rand() % chop) * pow(10.0, float(perk))) / pow(10.0, float(perk)); }
I don't see why people think Chuck Norris is so awesome. If he was really as great as they say, he would be over here slamming my head into the keybsk;lah;flksalfksdnlcslcnsldk;acklsd;glfbaskfl
/* When I wrote this, only God and I understood what I was doing... Now, God only knows */
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.
I did read it quite a while ago, but I figured out that rand() was producing pretty much the same thing as her version of rand(). All I have to do is call srand() every 1k calls to rand().
I don't see why people think Chuck Norris is so awesome. If he was really as great as they say, he would be over here slamming my head into the keybsk;lah;flksalfksdnlcslcnsldk;acklsd;glfbaskfl
/* When I wrote this, only God and I understood what I was doing... Now, God only knows */
Calling srand again after calling it the first time will NOT improve the distribution of your sequence - it will restart the sequence with a different seed, and depending on the seed value, it may give you the same sequence as last time or a different sequence. But it won't make the distribution any better.
--
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.