Random 如何获得x位置的唯一编号?

Random 如何获得x位置的唯一编号?,random,bitmap,android-canvas,Random,Bitmap,Android Canvas,我试图得到一个唯一的随机x位置来绘制位图,唯一的问题是随机数非常相似。因此,如何使这些唯一的数字彼此不同,每个数字之间有5个数字,顺序应该是5 10 15 20 25 private String generateXPoistion(String poistion, int numberaOfDigits) { for(int i=0;i<numberaOfDigits;i++) { pois

我试图得到一个唯一的随机x位置来绘制位图,唯一的问题是随机数非常相似。因此,如何使这些唯一的数字彼此不同,每个数字之间有5个数字,顺序应该是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);
        }
你在哪里

poistion +=  randomGenerator.nextInt(9) + 1
换成

poistion +=  5 * (randomGenerator.nextInt(9) + 1)

第1,2,3,。。。将缩放到5,10,15,…

生成顺序整数,然后将其乘以所需的交错距离5。我将尝试解决这个问题。