![]() |
![]() |
#2 (permalink) |
Riiiiight........
|
Here is a state of the art random number generator. Practically industrial strength. The output comes out in the form of a uniform random variable though, so if you need other probability distributions, you have to obtain them from the uniform variable in the usual way (check out simulation textbooks and resources if you need the 'recipes'). It is also not hard converting uniform r.v's into integers. just do a ceiling on the r.v.
Also, it only outputs a single number at a time, but I'm sure you can put it into an array yourself. Check out the RngStream link from here.... http://www.iro.umontreal.ca/~simardr/ Here are the links to the C and C++ files themselves. http://www.iro.umontreal.ca/~lecuyer/myftp/streams00/ |
![]() |
![]() |
#4 (permalink) | |
Banned
Location: 'bout 2 feet from my iMac
|
why not just generate numbers w/ stdlib.h then put them into an array?
Quote:
|
|
![]() |
![]() |
#7 (permalink) |
Psycho
Location: Rotterdam
|
The rand command works!
Check out the source code: #include <stdio.h> #define MAX 100 int a[MAX]; int rand_seed=10; /*Returns random number between 0 and 32767.*/ int rand() { rand_seed = rand_seed * 1103515245 +12345; return (unsigned int)(rand_seed / 65536) % 32768; } int main() { int i,t,x,y; /* fill array */ for (i=0; i < MAX; i++) { a[i]=rand(); printf("%d\n",a[i]); } return 0; } Comment: #define MAX 100, the size of the array is 100. int rand_seed=10, by changing the the value of the seed you will get an array with other random ganerated numbers. Thank you all for helping me!
__________________
Thumbs up ![]() |
![]() |
![]() |
#8 (permalink) |
Psycho
Location: London...no longer a student
|
a thread on random number generators and no has mentioned that it is in reality only possible to create a pseudo random number!!! the pedantic of us must have missed this one!
__________________
"Never underestimate a dumb question"-- Brandon Boyd |
![]() |
![]() |
#9 (permalink) | |
Addict
Location: Ottawa, ON, Canada
|
Quote:
I was going to mention pseudo-random numbers. Really. I was ![]()
__________________
"A witty saying proves nothing" - Voltaire |
|
![]() |
![]() |
#12 (permalink) |
undead
Location: nihilistic freedom
|
Actually, if you wanna make a really badass random number generator you should throw in a little entropy. For example, instead of using your constants: 1103515245, 12345, & 65536, you could form a function based on current disk i/o, cpu usage, cpu temperature, fan speed, etc... A little bit of hardware randomness will get you closer to truely random.
![]() |
![]() |
![]() |
#14 (permalink) | |
Addict
Location: Ottawa, ON, Canada
|
Quote:
![]()
__________________
"A witty saying proves nothing" - Voltaire |
|
![]() |
Tags |
generator, number, random |
|
|