Thread Tools Search this Thread
Top Forums Programming rand()
# 1  
Old 09-11-2002

Hi all,
Is the rand() function in C uniform or normal distribution. If it is unform, is there a random function that is normal.
Thanks and Regards
# 2  
Old 09-11-2002
The man page for rand says that it is a "multiplicative congruential" random number generator. That algorithm yields roughly a uniform distribution, but it's a lousy implementation of a lousy algorithm. It certainly does not produce anything at all like a normal distribution.

You should also have a function called drand48 which is a "linear congruential" random number generator. This also yields a uniform distribution, but the algorithm and implementation are much better than rand.

rand really should not be used in new code.

But unix doesn't have random number generators for other distributions. If you need a normal distribution maybe you can find some freeware by searching on google.

Also, you may want to read "The Art of Computer Programming Volume 2 Seminumerical Algorithms" by Donald Knuth. It shows how to transform uniform random numbers into random numbers with other distributions including normal.
# 3  
Old 09-12-2002
Thank you very much!!
Login or Register to Ask a Question

Previous Thread | Next Thread

1 More Discussions You Might Find Interesting

1. Programming

fork and rand()

Hi, I want build 10 processus with fork and that each processus write a value betwen 0 and 9 , but each processus send the same value . So my code ,you can compile and try . #include <time.h> #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/ipc.h> ... (7 Replies)
Discussion started by: carton99
7 Replies
Login or Register to Ask a Question