Hi
I have searched and found how you do it with rand function and mod
IDE also suggests _FRND
there is also mersienne twister and others
whats the best for a quiz?
not want end up with a repeative random generator or exactly the same quiz
M
Hi
I have searched and found how you do it with rand function and mod
IDE also suggests _FRND
there is also mersienne twister and others
whats the best for a quiz?
not want end up with a repeative random generator or exactly the same quiz
M
There are, at least, 2 dozens of "good" PRNGs out there (see here). There is no PRNGs truly random (the P stands for PSEUDO), but the quality of the randomness is pretty close to "random" as one's can get.
And lack of repetition is not a criteria for the "best" quality of randomness. Take a coin toss as an example: You have only 2 possible values and they will repeat a lot, it doesn't mean the set isn't random... Same thing as D6 dice toss...
If you want a "real' random generator for computers you'll need an external source of entropy (and luckly, Intel and AMD processors has an "internal" external source - hehe -- using RDRAND instruction or _rdrand??_step() function you'll get random BITS sequences).
My preference, due to simplicity and speed are, for PRNGs, LCG and xorshift128+.
If you don't care about speed and want to get a "truly" random values, in Linux/BSD/OSX you can do:
Code:#include <fcntl.h> #include <unistd.h> // Assume /dev/urandom is always readable and we have enough // file descriptors left... Should test this claims before using // the routine. unsigned int getUint32Random( void ) { unsigned int v; int fd; // /dev/random and /dev/urandom, nowadays, uses rdrand on // Intel and AMD platforms... It's not garantee it is truly // random in all Unixes, but the kernel tries to garantee a // flow of random bits. // // You can use /dev/random, but this other device will // try to garantee entropy (and could block from time to time). fd = open( "/dev/urandom", O_RDONLY ); read( fd, &v, sizeof v ); close( fd ); return v; }
Last edited by flp1969; 04-20-2019 at 07:09 AM.
I'd say /dev/urandom is guaranteed not to be "truly random" by design parameters, but that generally doesn't matter since a cryptographically secure PRNG seeded with sufficient entropy should be practically indistinguishable from a "truly random" source, whether it is used as a fallback or as an integral part of the system.Originally Posted by flp1969
Last edited by laserlight; 04-20-2019 at 02:19 PM.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
thanks Laserlight
it seems to work good now produce random facts
Next step: random generator that generates same seed= same world?
you tell me you can C,why dont you C your own bugs?
Code://maybe this work ///////////////////////////////////////////// //srand and rand in a feedback loop,starting with srand(1) or start with a big number while (finished==true){ R=Rand(); srand(R); x=R%numberofrandoms; drawsomething(x); if screenfilled()==1 { finished=True; } }
you tell me you can C,why dont you C your own bugs?
this purpose is to generate lots of trees for a forest,buildings and such on a map until its filled,so you always endup with same
you tell me you can C,why dont you C your own bugs?