-5

こんにちは、誰でも以下の私のコードを手伝ってくれますか。その下のイテレータに乱数を実装しようとしています。ここで、数値「100」は1〜100の乱数になります。

どんな助けでも大いに感謝します

ダニエル

Random randomGenerator = new Random();
    for (int idx = 1; idx <= 100; ++idx){
      int randomInt = randomGenerator.nextInt(100);

    }

      Iterator<Rectangle> iter = clouds.iterator();
      while(iter.hasNext()) {
         Rectangle cloud = iter.next();
        //this effects the speed of downward movement
         cloud.x -= 100 * Gdx.graphics.getDeltaTime();
         if(cloud.x + 80 < 0) iter.remove();

      }
4

1 に答える 1

0

それはかなり些細なことです。

Random r = new Random();

Iterator<Rectangle> iter = clouds.iterator();

while(iter.hasNext()) {
  Rectangle cloud = iter.next();
  //this effects the speed of downward movement
  cloud.x -= (r.nextInt(100) + 1) * Gdx.graphics.getDeltaTime();

  if(cloud.x + 80 < 0) iter.remove();
}

java.util.Randomのドキュメントを参照してください。

于 2012-06-12T08:32:00.310 に答える