TIP: Click on subject to list as thread! ANSI
echo: nthelp
to: Geo
from: Paul Ranson
date: 2004-12-05 23:05:14
subject: Re: c++ help

From: "Paul Ranson" 

The C++ library function 'random_shuffle' uses, by default, 'rand'. At
least in the MS VC++ implementation. The option is to use a function of
your own devising, but that's a bit more advanced. The great thing about
the C++ STL is that you can start to use it without too much complexity, as
long as you don't get bogged down in the documentation.The sort function
for instance is way harder in C, or DIY.

You could dig up a better seed for rand, perhaps the lower 32 bits of the
64 bit processor clock counter?

LARGE_INTEGER seed ;
::QueryPerformanceCounter ( &Seed ) ;
::srand ( seed.LowPart ) ;

This is incrementing at processor clock rate, so you're counting 4 billion
roughly every 2 seconds on a reasonably modern machine. Even a very precise
mouse finger would have difficulty generating a sequence of similar seeds.

Paul

"Geo"  wrote in message
news:41b370e7$1{at}w3.nls.net...
> "Paul Ranson"  wrote in message
> news:41b3660d{at}w3.nls.net...
>
>>>I'm pretty sure that that uses the 'rand' function internally, so your
> method for setting the generator would still apply.
>
> it's important to use an unusual randomizer routine because there are no
> real random numbers. By that I mean of 10 people wrote a program to do the
> same thing, and we all used the same randomize routine then wouldn't the
> results all be similar (based on time only)? Anyway, that's the logic
> behind
> my goofy randomize loop.
>
> So far it's working great and I really appreciate the solution to the zero
> problem as well. I'm now working on the mega millions generator. Will post
> to binaries once I'm done.
>
> Geo.
>
>

--- BBBS/NT v4.01 Flag-5
* Origin: Barktopia BBS Site http://HarborWebs.com:8081 (1:379/45)
SEEN-BY: 633/267 270 5030/786
@PATH: 379/45 1 396/45 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.