[Blindapple] Slightly OT - shuffling routine
Aaron Howell
aaron at kitten.net.au
Wed Nov 24 07:50:39 EST 2004
My apologies, it seems I really can't read tonight.
Try the folowing
decksize=52
dim deck(decksize-1)
i=0
j=0
k=0
for i = 1 to decksize
deck(i-1)=i
next
for i = 0 to (decksize-1)
j=ran(decksize-1)
k=deck(i)
deck(i)=deck(j)
deck(j)=k
next
(Tested under yabasic under linux but should be relatively portable).
Regards
Aaron
On Wed, Nov 24, 2004 at 07:10:54AM -0500, Jayson Smith wrote:
> Um. That's in C. I'm looking for something in Basic. Sorry about that!
> Jayson.
>
> ----- Original Message -----
> From: "Aaron Howell" <aaron at kitten.net.au>
> To: "Blind Apple Discussions" <blindapple at jaybird.no-ip.info>
> Sent: Wednesday, November 24, 2004 7:01 AM
> Subject: Re: [Blindapple] Slightly OT - shuffling routine
>
>
> > What you want it something like...
> >
> > shuffle(int deck[]){
> > int i, j, k;
> > for (i=0, i=sizeof(deck), i++){
> > j=random()%sizeof(deck);
> > k=deck[j];
> > deck[j]=deck[i];
> > deck[i]=k;
> > }
> > }
> > I might be slightly out on the random line but that's the general formula
> anyway (its been a long day, compile and test).
> > Regards
> > Aaron
> > On Wed, Nov 24, 2004 at 04:26:21AM -0500, Jayson Smith wrote:
> > > Hi,
> > > I'm writing a game in Basic for the PC. The game will require me to
> > > randomize the order of arrays of strings. The strings themselves will
> be
> > > contained in data statements in the program, and will be read into the
> > > arrays. I just need to shuffle them at the beginning of the game. What
> > > would be the easiest way to do this? I want shuffled arrays rather than
> > > just using a random element from the arrays each time as I don't want
> > > repeats. I plan to reshuffle whenever the last elements of the shuffled
> > > arrays are used.
> > > Jayson.
> > >
> > >
> > > _______________________________________________
> > > BlindApple mailing list
> > > BlindApple at jaybird.no-ip.info
> > > http://jaybird.no-ip.info/mailman/listinfo/blindapple
> > _______________________________________________
> > BlindApple mailing list
> > BlindApple at jaybird.no-ip.info
> > http://jaybird.no-ip.info/mailman/listinfo/blindapple
> >
>
> _______________________________________________
> BlindApple mailing list
> BlindApple at jaybird.no-ip.info
> http://jaybird.no-ip.info/mailman/listinfo/blindapple
More information about the BlindApple
mailing list