random picking

Blitz3D Forums/Blitz3D Beginners Area/random picking

The following little program generates 3 random numbers in the range of 0 to 16 (as you need) and stores them in an array. The purpose of the array is to enable a check to be made on subsequent random number generations to ensure that the random number hasn't already been chosen. Should be easy enough to convert for your program.

SeedRnd MilliSecs()

Dim gen(2)
char=-1

For spawn=0 To 2
	While char<0
		char=Rand(0,16)
		If spawn>0 Then
			For i=0 To spawn-1
				If gen(i)=char Then char=-1
			Next
		EndIf
	Wend
	gen(spawn)=char
	char=-1
Next

For i=0 To 2
	Print "Character "+(i+1)+" is "+gen(i)
Next

WaitKey:End