Question:
how to write code to generate random numbers in c without using the default random function?
2012-08-12 22:14:01 UTC
plz help me get the code....i dint find it on net
Four answers:
Bob
2012-08-12 23:27:42 UTC
This website has some information on the algorithm used in the c programming language's rand() function:



http://stackoverflow.com/questions/1026327/what-common-algorithms-are-used-for-cs-rand
roger
2012-08-13 08:17:22 UTC
You did not look very hard



If you search for: "random number generator code"

you get:



http://www.cs.wm.edu/~va/software/park/



on the first hit.....







If you want something more complex :

Here is the code for Mersenne Twistor:



http://root.cern.ch/root/html/src/TRandom3.cxx.html
Blackcompe
2012-08-12 23:58:30 UTC
Basing an implementation off an LCG would be a smart way to go about it. C's rand() is an LCG.
brogden
2016-08-02 03:26:39 UTC
Comprise #incorporate #incorporate int random() int r; r=rand()%50+1; return r; primary() int a[20]; for(int i=zero;i<=20;i++) a[i]=random(); cout<<"showing teh random numbers"; for(i=zero;i<=20;i++) cout<


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...