Code archives/Algorithms/Look for duplication

This code has been declared by its author to be Public Domain code.

Download source code

Look for duplication by Nicstt2005
handles any number of numbers, code has been designed so changing the constants will change the list of numbers searched through

TILES_Pos and TILES_Neg are the two constants added together to give total quantity of numbers to check, could be altered to make 1

mult# - works out the number of iterations through the code to get a clean run

howManyTilesX(0) howManyTilesY(0) are the arrays that store numbers to be checked for duplication - the zero array of each stores the length of each array

random = Rnd(0,16) when it finds a duplicate number = chooses a new one
Until random > 0 And random < 16 - it seems that the first and last number are picked less frequently than others, or at least this used to be the case. Ive not checked if that is still the case.

c = Rnd(0,1) - as it doesnt matter if one of the arrays is equal, randomly picks one to change
check = 0
multiplier# = ((Float(TILES_Pos) + Float(TILES_Neg)) / 2.0) - 0.5
mult# = multiplier# * Float(howManyTilesX(0))
Repeat
     For a = 1 To howManyTilesX(0)
	For b = a+1 To howManyTilesX(0)
		If howManyTilesX(a)	= howManyTilesX(b) And howManyTilesY(a) = howManyTilesY(b) 
             		Repeat
				random = Rnd(0,16)
			Until random > 0 And random < 16
			c = Rnd(0,1)
			If c = 1
				howManyTilesX(b) = random
			Else
				howManyTilesY(b) = random
			EndIf
		Else
			check = check + 1
		EndIf
	Next
     Next
     If check <> Int mult# Then check = 0
Until check = Int mult#

Comments

None.

Code Archives Forum