[Blindapple] Slightly OT - shuffling routine

Aaron Howell aaron at kitten.net.au
Wed Nov 24 07:01:42 EST 2004


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



More information about the BlindApple mailing list