Random number generator

Reply

Join Date: Dec 2008
Posts: 1
Reputation: DIYON is an unknown quantity at this point 
Solved Threads: 0
DIYON DIYON is offline Offline
Newbie Poster

Random number generator

 
0
  #1
Dec 27th, 2008
Hi,
Can anyone help me please!!!
I'm new to C++ and trying to do my coursework......I want to know how to write a programme to generate random numbers uniformly distributed between 0 and 1.
Any help is much appreciated.
Thank you,
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 206
Reputation: grumpier has a spectacular aura about grumpier has a spectacular aura about 
Solved Threads: 31
grumpier grumpier is offline Offline
Posting Whiz in Training

Re: Random number generator

 
0
  #2
Dec 27th, 2008
Look up the standard C functions in the C standard library, through <stdlib.h> or (in C++, through the <cstdlib> header). srand(int) is used to initially seed the generator. rand(), when subsequently called in a loop, produces pseudorandom integers in the range 0 to RAND_MAX.

Convert those integers returned from rand() to type double, and divide by RAND_MAX to get values in the range 0 to 1.
Last edited by grumpier; Dec 27th, 2008 at 1:55 am.
Right 98% of the time, and don't care about the other 3%.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC