I am trying to get a unique random x position to draw a bitmap, the only problem I have is that the random numbers are very similar. so how to make these unique numbers different from each others by 5 number between each number, the sequence should be like 5 10 15 20 25.
private String generateXPoistion(String poistion, int numberaOfDigits)
{
for(int i=0;i<numberaOfDigits;i++)
{
poistion += randomGenerator.nextInt(9) + 1; // the 1 to avoid zero
}
return poistion;
}
//In the method storeApp, I am using the KeyValue of the hashMap as an x position to draw the bitmap.
public void storeApple(Apple apple)
{
String newId = generateXPoistion("",3);
while(appleMap.get(newId) != null )
{
newId = generateXPoistion("",3);
}
int foo = Integer.parseInt(newId);
apple.setPos(foo);
appleMap.put(newId,apple);
}
Aucun commentaire:
Enregistrer un commentaire