Visit Jeremy's Blog.
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, 10: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, 01:49 PM   #2
Registered: Jan 2005
Distribution: Archlinux, Debian, Centos
Posts: 219

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, 09: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 05:08 PM
Generating Gaussian Random Numbers R00ts Programming 2 08-11-2004 12:51 AM
Music samples jrdioko Linux - Newbie 4 07-25-2004 06:54 PM
MySQL tips and samples mchirico Linux - Newbie 0 04-16-2004 06:56 PM
Generating random numbers for C program J-Stew Programming 14 02-06-2004 05:49 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:53 PM.

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