prince_kenshi
03-23-2001, 02:09 PM
I'm trying to make a card program and I want it to draw 20 random cards at once. Basically it gets a random number between 1 and 13 and will be changed to a card later. The random seed seems to only change each second but I want all the cards at once. Since just getting a random number with rand() got the same number for each card, I made a more complex algorithm, but it's still the same card each time. All I want is something complex enough that the player can't figure out what the next card will be, even if he knows the program's source. Can someone take a look at this segment of it and tell me why it keeps repeating cards and how to fix it? (It draws different cards each time I execute it, just not throughout the same execution.)
short int my_hand[20,2];
short int comp_hand[20,2];
char cards[2];
int seed2;
srand((unsigned)time(NULL));
seed2=rand()%100+50;
for(cards[0]=0;cards[0]<20;cards[0]++)
my_hand[cards[0],0]=(rand()+(cards[0]*seed2)^2)%13+1;
for(cards[0]=0;cards[0]<20;cards[0]++)
comp_hand[cards[0],0]=(rand()+(cards[0]*seed2)^2)%13+1;
[ 23 March 2001: Message edited by: prince_kenshi ]
short int my_hand[20,2];
short int comp_hand[20,2];
char cards[2];
int seed2;
srand((unsigned)time(NULL));
seed2=rand()%100+50;
for(cards[0]=0;cards[0]<20;cards[0]++)
my_hand[cards[0],0]=(rand()+(cards[0]*seed2)^2)%13+1;
for(cards[0]=0;cards[0]<20;cards[0]++)
comp_hand[cards[0],0]=(rand()+(cards[0]*seed2)^2)%13+1;
[ 23 March 2001: Message edited by: prince_kenshi ]