# How to randomly spawn a Rect on x position (android studio)?

I want to draw a rect with a 50x50 size, however I want it to appear randomly on the x position. Where should i set the x position?

This is how i set my rectangle.

rectangle.set(50, 50, 100, 100);


I've done several changes on this setting the but I can't figure it out.

• generate a random number, assign that number to x and pass x to rectange.set Feb 5 '17 at 15:44

rectangle.set(randomX, 50, randomX + 50, 100);

Where randomX is the random value.