LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

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

Rep: Reputation: 15
Unhappy 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.
 
Old 07-20-2005, 01:49 PM   #2
traene
Member
 
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, 09:35 AM   #3
aru_04
LQ Newbie
 
Registered: Nov 2004
Posts: 24

Original Poster
Rep: Reputation: 15
Thanks a lot!
aru
 
  


Reply


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


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

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