### Author Topic: Explain this!  (Read 40 times)

#### OlDosLover

• Hero Member
• Posts: 3845
• OlDosLover
##### Explain this!
« on: April 21, 2013, 01:24:39 AM »
Hi all,
In this program i am generating the numbers 1 to 64 and then trying to shuffle those numbers like a deck of cards. For some reason it often shows duplicate numbers and missing numbers but at the end test stage it shows only one of each number number is generated. Its got me stumped!
Code: [Select]
`REMDEFINT A-ZDIM SHARED MixedUp(1 TO 64) AS INTEGERDIM SHARED Counter(1 TO 64) AS INTEGERFOR t = 1 TO 64  MixedUp(t) = t  PRINT MixedUp(t),NEXT tSLEEPCLS'RANDOMIZE TIMERFOR t = 1 TO 64  z = INT(RND * 64) + 1  'SWAP MixedUp(z), MixedUp(t)  Temp1 = MixedUp(t)  Temp2 = MixedUp(z)  MixedUp(z) = Temp1  MixedUp(t) = Temp2  PRINT MixedUp(t),  'PRINT z,NEXTSLEEPCLSFOR t = 1 TO 64  z = MixedUp(t)  Counter(z) = Counter(z) + 1NEXT tFOR t = 1 TO 64  PRINT Counter(t),NEXT tSLEEPSYSTEM`OlDosLover.

#### Mrwhy

• Hero Member
• Posts: 2882
• My Dad called me Mr Why when I was 5.
##### Re: Explain this!
« Reply #1 on: April 21, 2013, 01:32:17 AM »
The most common "error" in progs like this is to test an object against itself instead of ignoring that identity each time it arises.

#### OlDosLover

• Hero Member
• Posts: 3845
• OlDosLover
##### Re: Explain this!
« Reply #2 on: April 21, 2013, 01:34:51 AM »
Hi all,
Ahh i figured it out. Im printing the new shuffled index and it shows a duplicated number. The solution was to wait till the loop is finished and then to print the shuffled numbers and then they show correctly with no duplicates. A silly thing i over looked!
OlDosLover.