Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C++ Random Number Generator?

Status
Not open for further replies.

cloudy

ISP
Jul 14, 1999
17
US
<br>
<br>
I don't program personally. I prefer the hardware side of the universe ;-)<br>
However, I have a friend trying to learn C++, and asked if I might help. He<br>
is desperate. Anyway, his uncle tried to help him, and this is the gist of<br>
his message.......<br>
<br>
Remember, you are talking about a computer. Given the same<br>
&gt;starting point, a computer will always generate the same sequence of<br>
&gt;numbers from a random number generator. Secondly, the random<br>
number<br>
&gt;generator does not start to evenly distribute the numbers until the<br>
&gt;random number generator has run at least 50 times. The best way to<br>
make<br>
&gt;the random number generator to be truly random is to run the generator<br>
&gt;several times before you use the generator for your end purpose. My<br>
&gt;favorite idea is to read the computer's clock, multiple the minutes<br>
&gt;times the seconds, add the hours, add fifty, and run the random<br>
number<br>
&gt;generator that many times before using the generator.<br>
&gt;<br>
<br>
My friend seems to want to find some c++ code that will do what is<br>
described above. It seems like it would only be a few lines of code, but<br>
again I am no programmer beyond just having had courses in college.<br>
Could anyone generate a few lines of code that will do the above?
 
Seed:
LARGE_INTEGER gint;
QueryPerformanceCounter(&gint);
srand(gint.LowPart );


QueryPerformanceCounter is much better than the clock
(ticks millions of times/second)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top