random picking
Blitz3D Forums/Blitz3D Beginners Area/random picking
| ||
Hi all, Can anyone please help with a solution to this? I dont want to pick the same mesh twice or three times from the character array during the loop... This is very basically what I'm doing... Bob = loadmesh("bob.b3d") ;character 1 Fred = loadmesh("Fred.b3d");character 2 and so on up to 16 Jill = loadmesh("Jill.b3d");character 16 Dim characterarray$(16) characterarray(0) = Bob characterarray(1) = Fred ;...and so on up to 16 characterarray(16) = Jill Then I set up a loop to do this... For spawn = 0 To 2 r.character = New character randcharacter = Rand(0,16) mesh = characterarray$(randcharacter) r\mesh = CopyEntity(mesh) Next So what I'm doing is generating 3 random characters from an array of 16. What Im trying to achieve is how to NOT pick the same character twice or three times during the loop. Any help on how to do this would be appreciated. Thanks. |
| ||
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 |
| ||
Ah thank you JazzieB, I'll give it a go. |