From: "Geo"
This is a multi-part message in MIME format.
------=_NextPart_000_000F_01C4DAEB.1657F790
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Oh nevermind, you are only sorting the balls I'm using not the whole = batch.
Geo.
"Paul Ranson" wrote in message =
news:41b366f5{at}w3.nls.net...
One neat thing you could do,
#include
int balls [ 50 ] ;
for ( int i =3D 0; i < 50; ++i )
balls [ i ] =3D i + 1 ;
std::random_shuffle ( balls, balls + 50 ) ;
std::sort ( balls, balls + 3 ) ;
m_pick4.Format ( "%d-%d-%d-%d", balls [ 0 ], balls[ 1 ], balls[ 2 ], =
balls[ 3 ]) ;
to output the chosen numbers in ascending order...
Paul
"Paul Ranson" wrote in message =
news:41b3660d{at}w3.nls.net...
'rand' returns a pseudo random number between 0 and 32767. So in =
your application 8 and 9 should come up slightly less often than 0-7. To =
do a lotto type thing I think a shuffle is appropriate, luckily C++ =
contains the exact function you want....
#include
int balls [ 50 ] ;
for ( int i =3D 0; i < 50; ++i )
balls [ i ] =3D i + 1 ;
std::random_shuffle ( balls, balls + 50 ) ;
m_pick4.Format ( "%d-%d-%d-%d", balls [ 0 ], balls [ 1 ], balls [ 2 =
], balls [ 3 ]) ;
etc.
I'm pretty sure that that uses the 'rand' function internally, so =
your method for setting the generator would still apply. I'll take a = look
later. This approach also deals with the '0' issue since most = lotteries
choose from 1-n rather than 0-n-1... You can supply your own = random
generator to 'random_shuffle' but this is syntactically a bit = trickier.
I found http://www.paradisepoker.com/shuffling.html interesting, if =
you want to do this properly then there are quite a lot of things to = think about.
Paul
------=_NextPart_000_000F_01C4DAEB.1657F790
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Oh nevermind, you are only sorting the =
balls I'm=20
using not the whole batch.
Geo.
"Paul Ranson" <paul{at}barkto.com>">mailto:paul{at}barkto.com">paul{at}barkto.com>
wrote in =
message news:41b366f5{at}w3.nls.net...
One neat thing you could
do,
#include=20
<algorithm>
int balls [ =
50 ]=20
;
for ( int i =
=3D 0; i < 50;=20
++i )
=
balls [ i ] =3D=20
i + 1 ;
std::random_shuffle (=20
balls, balls + 50 ) ;
std::sort ( balls, =
balls + 3=20
) ;
m_pick4.Format (=20
"%d-%d-%d-%d", balls [ 0 ], balls[ 1 ], balls[ 2 ], balls[ 3 ]) =
;
to output the chosen numbers in ascending order...
Paul
"Paul Ranson" <paul{at}barkto.com>">mailto:paul{at}barkto.com">paul{at}barkto.com>
wrote in =
message news:41b3660d{at}w3.nls.net...
'rand' returns a pseudo random number between 0 =
and 32767.=20
So in your application 8 and 9 should come up slightly less often =
than 0-7.=20
To do a lotto type thing I think a shuffle is =
appropriate, luckily C++=20
contains the exact function you want....
#include=20
<algorithm>
int balls [ =
50 ]=20
;
for ( int i =
=3D 0; i <=20
50; ++i )
balls [ i ]=20
=3D i + 1 ;
std::random_shuffle (=20
balls, balls + 50 ) ;
m_pick4.Format (=20
"%d-%d-%d-%d", balls [ 0 ], balls [ 1 ], balls [ 2 ], balls [ 3 ])=20
;
etc.
I'm pretty sure that that uses the 'rand' =
function=20
internally, so your method for setting the generator would still =
apply. I'll=20
take a look later. This approach also deals with the '0' issue since =
most=20
lotteries choose from 1-n rather than 0-n-1... You can supply your =
own=20
random generator to 'random_shuffle' but this is syntactically a bit =
trickier.
I found http://www.paradisep" target="new">http://www.paradisep=">http://www.paradisepoker.com/shuffling.html">http://www.paradisep=
oker.com/shuffling.html=20
interesting, if you want to do this properly then there are quite a =
lot of=20
things to think about.
Paul
------=_NextPart_000_000F_01C4DAEB.1657F790--
--- 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
|