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

From: "Geo" 

This is a multi-part message in MIME format.

------=_NextPart_000_001B_01C4DAE7.0F6C68C0
Content-Type: text/plain;
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

doesn't the sort undo the shuffle?

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_001B_01C4DAE7.0F6C68C0
Content-Type: text/html;
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable








doesn't the sort undo the =
shuffle?
 
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_001B_01C4DAE7.0F6C68C0-- --- 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™.