mardi 7 novembre 2017

NextInt() for the java.util.random class isn't giving a random number in a while loop

The rectangles created by this code all have the same dimensions. I'm not sure why they aren't a random int between the numbers I set.

Random r = new Random();
        buildings = new Vector<Rectangle>();
        while( xEnd < 700 )
        {
            cur = new Rectangle( r.nextInt(30) + 20, 
                                r.nextInt(30) + 70 );
            cur.setLocation( xEnd, 400 - cur.getHeight() );
            cur.setFillColor( Color.gray );
            cur.setFrameColor( Color.gray.darker().darker() );
            cur.setFrameThickness( 4 );
            buildings.add(cur);
            xEnd = cur.getXLocation() + cur.getWidth();
        }

Any Ideas?




Aucun commentaire:

Enregistrer un commentaire