Did you know LQ has a Linux Hardware Compatibility List?
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-20-2005, 09:25 AM   #1
LQ Newbie
Registered: Nov 2004
Posts: 24

Rep: Reputation: 15
Unhappy code for generating random samples!

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.
Old 07-20-2005, 12:49 PM   #2
Registered: Jan 2005
Distribution: Archlinux, Debian, grml
Posts: 210

Rep: Reputation: 33
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.
Old 07-21-2005, 08:35 AM   #3
LQ Newbie
Registered: Nov 2004
Posts: 24

Original Poster
Rep: Reputation: 15
Thanks a lot!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
generating random numbers in C abk4523 Programming 20 01-10-2011 04:08 PM
Generating Gaussian Random Numbers R00ts Programming 2 08-10-2004 11:51 PM
Music samples jrdioko Linux - Newbie 4 07-25-2004 05:54 PM
MySQL tips and samples mchirico Linux - Newbie 0 04-16-2004 05:56 PM
Generating random numbers for C program J-Stew Programming 14 02-06-2004 04:49 AM

All times are GMT -5. The time now is 01:36 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration