5 DIM trp(18000, 6): PRINT TIME$

10 RANDOMIZE TIMER

20 r = INT(RND * 12) + 1: s = INT(RND * 12) + 1: t = INT(RND * 12) + 1

30 u = INT(RND * 12) + 1: v = INT(RND * 12) + 1: w = INT(RND * 12) + 1

40 IF r = s OR r = t OR r = u OR r = v OR r = w THEN 20

50 IF s = t OR s = u OR s = v OR s = w THEN 20

60 IF t = u OR t = v OR t = w THEN 20

70 IF u = v OR u = w THEN 20

80 IF v = w THEN 20

90 ef = 0: FOR i = 1 TO 18000: IF ef <> 0 THEN GOTO 110 'advance loop _LIMIT (4096000):

100 IF trp(i, 1) = 0 THEN ef = i

110 NEXT i

120 IF ef = 0 THEN 140 'process existing selections for opposites

130 trp(ef, 1) = r: trp(ef, 2) = s: trp(ef, 3) = t: trp(ef, 4) = u: trp(ef, 5) = v: trp(ef, 6) = w: GOTO 20

140 'process selections for duplicates

150 c = 0: dup = 0: LOCATE 2, 1: PRINT "A"; TIME$: FOR i = cl TO 17999: FOR j = 1 TO 18000: ' _LIMIT (16384000)

155 IF i = j OR c <> 0 THEN 235

160 IF trp(i, 1) = trp(j, 1) OR trp(i, 1) = trp(j, 2) OR trp(i, 1) = trp(j, 3) OR trp(i, 1) = trp(j, 4) OR trp(i, 1) = trp(j, 5) OR trp(i, 1) = trp(j, 6) THEN dup = dup + 1

170 IF trp(i, 2) = trp(j, 1) OR trp(i, 2) = trp(j, 2) OR trp(i, 2) = trp(j, 3) OR trp(i, 2) = trp(j, 4) OR trp(i, 2) = trp(j, 5) OR trp(i, 2) = trp(j, 6) THEN dup = dup + 1

180 IF trp(i, 3) = trp(j, 1) OR trp(i, 3) = trp(j, 2) OR trp(i, 3) = trp(j, 3) OR trp(i, 3) = trp(j, 4) OR trp(i, 3) = trp(j, 5) OR trp(i, 3) = trp(j, 6) THEN dup = dup + 1

190 IF trp(i, 4) = trp(j, 1) OR trp(i, 4) = trp(j, 2) OR trp(i, 4) = trp(j, 3) OR trp(i, 4) = trp(j, 4) OR trp(i, 4) = trp(j, 5) OR trp(i, 4) = trp(j, 6) THEN dup = dup + 1

200 IF trp(i, 5) = trp(j, 1) OR trp(i, 5) = trp(j, 2) OR trp(i, 5) = trp(j, 3) OR trp(i, 5) = trp(j, 4) OR trp(i, 5) = trp(j, 5) OR trp(i, 5) = trp(j, 6) THEN dup = dup + 1

210 IF trp(i, 6) = trp(j, 1) OR trp(i, 6) = trp(j, 2) OR trp(i, 6) = trp(j, 3) OR trp(i, 6) = trp(j, 4) OR trp(i, 6) = trp(j, 5) OR trp(i, 6) = trp(j, 6) THEN dup = dup + 1

230 IF dup = 6 THEN trp(j, 1) = 0: c = i: cl = i - 1: IF cl < 1 THEN cl = 1

235 dup = 0: NEXT j, i: IF c <> 0 THEN LOCATE 3, 1: PRINT " ": LOCATE 3, 1: PRINT c; TIME$: GOTO 20

237 cl = 1

240 'process selections for opposites

250 sf = 0: LOCATE 3, 1: PRINT "B"; TIME$: FOR i = cl TO 17999: FOR j = i TO 18000: ' _LIMIT (16384000)

255 IF c <> 0 THEN 330

260 IF trp(i, 1) = trp(j, 1) OR trp(i, 1) = trp(j, 2) OR trp(i, 1) = trp(j, 3) OR trp(i, 1) = trp(j, 4) OR trp(i, 1) = trp(j, 5) OR trp(i, 1) = trp(j, 6) THEN 330 'advance loop

270 IF trp(i, 2) = trp(j, 1) OR trp(i, 2) = trp(j, 2) OR trp(i, 2) = trp(j, 3) OR trp(i, 2) = trp(j, 4) OR trp(i, 2) = trp(j, 5) OR trp(i, 2) = trp(j, 6) THEN 330 'advance loop

280 IF trp(i, 3) = trp(j, 1) OR trp(i, 3) = trp(j, 2) OR trp(i, 3) = trp(j, 3) OR trp(i, 3) = trp(j, 4) OR trp(i, 3) = trp(j, 5) OR trp(i, 3) = trp(j, 6) THEN 230 'advance loop

290 IF trp(i, 4) = trp(j, 1) OR trp(i, 4) = trp(j, 2) OR trp(i, 4) = trp(j, 3) OR trp(i, 4) = trp(j, 4) OR trp(i, 4) = trp(j, 5) OR trp(i, 4) = trp(j, 6) THEN 330 'advance loop

300 IF trp(i, 5) = trp(j, 1) OR trp(i, 5) = trp(j, 2) OR trp(i, 5) = trp(j, 3) OR trp(i, 5) = trp(j, 4) OR trp(i, 5) = trp(j, 5) OR trp(i, 5) = trp(j, 6) THEN 330 'advance loop

310 IF trp(i, 6) = trp(j, 1) OR trp(i, 6) = trp(j, 2) OR trp(i, 6) = trp(j, 3) OR trp(i, 6) = trp(j, 4) OR trp(i, 6) = trp(j, 5) OR trp(i, 6) = trp(j, 6) THEN 330 'advance loop

320 trp(j, 1) = 0: sf = 1: c = j: cl = i

330 NEXT j, i

340 IF sf = 1 OR c > 0 THEN LOCATE 4, 1: PRINT c; TIME$: GOTO 20

350 'ouptut selections

355 OPEN "Random_Streets.txt" FOR OUTPUT AS #1

360 FOR i = 1 TO 18000

370 PRINT #1, trp(i, 1); trp(i, 2); trp(i, 3); trp(i, 4); trp(i, 5); trp(i, 6)

380 NEXT i: PRINT TIME$: CLOSE #1

INPUT a$

The above code will randomize 180000 sets of 6 digits ranging from 1 to 12, removing all duplicates and complete opposites from the list. I have gotten to the point where I would like more of these combinations and it is taking over 8 hours for the "de-duplicating" process to complete.

This is where I need help in simply making this code as efficient as possible so as to cut the time down to the maximum for its completion.

I am willing to accept a complete rewrite if the following is maintained:

1) The resulting sets of 6 numbers contain no duplicates: a) within themselves (AABCDE, BBACDE etc.), b) in any other element (AAAAAB and BAAAAA cannot both exist in the final list), c) no exact opposite duplication (1 2 3 4 5 6 and 7 8 9 10 11 12 are exact opposites and cannot exist together in the final list)

2) A simple notepad text file (.txt) is generated with all 180000 sets of numbers 6 to a line with no special characters at all

3) Compatibility with the QB64 (Windows Quick Basic) is maintained in the code

Of course I am able to accept workarounds with my existing code as well.

Thanks in advance for your help!

PS My apologies for using multiple IF...THEN statements instead of an additional FOR...NEXT loop but I wanted to make the logic as clear to myself as possible. :shrug: