LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   code for generating random samples! (http://www.linuxquestions.org/questions/programming-9/code-for-generating-random-samples-345000/)

aru_04 07-20-2005 09:25 AM

code for generating random samples!
 
Greetings,
lets come straight to the point.

i have to write a piece of code in C to generate "INDEPENDENT AND UNIFORM (RANDOM) SAMPLES" from a given interval.

since i am a complete zero when it comes to statistics, any help will be greatly appreciated.
thanks.

traene 07-20-2005 12:49 PM

There are different random number generators. However, for
some good random number you may use the glibc functions:

srand48(time(NULL); // initializing random number generator, may be used as
srand48(0); // to always get the same numbers. (for testing)
drand48(); // gives a double between 0 and 1.

int myNumber = (int) (drand48() * MAX_VALUE + 1.0); // for numbers between 1 and MAX_VALUE.

aru_04 07-21-2005 08:35 AM

Thanks a lot!
aru


All times are GMT -5. The time now is 06:51 AM.