Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
You will need to save each generated numbers into an array, and regenerate again and again until you have no clash.
This code is in python, but just to give you an idea:
Code:
import random
shooters={}
while len(shooters)<4:
id=random.randint(0,9999999)
while id in shooters.keys():
id=random.randint(0,9999999)
#end while
shooters[id]=True
#end while
print shooters
I use something like this to check availability of threads in a daemon.
When the thread is active, there is an shooters[id] value. When activity stops, the threads update shooters to remove it's id.
I needed random values without clash for this to work without conflicts.
__________________
Only a biker knows why a dog sticks his head out the window.
Last edited by tripy; 02-17-2009 at 07:13 AM..
|