sudde gameeef wrote:i am making a game where i need to create object only onces randomly. <br/>
i can get random number by random object. but not sure how to put in if statment. <br/>
Ramesh Pramuditha Rathnayake wrote:This will give the same result as in yours. But this contains no unnecessary codes...
Jesper de Jong wrote:Almost the same. The original code didn't print anything if x was exactly equal to 0, 100 or 200. Also, the condition (x < 300) is unnecessary, because r.nextInt(300) will always produce a number less than 300.
Anayonkar Shivalkar wrote:If you need to create random number only once (and especially if you are not dealing with a series of random numbers), I would suggest to use 'random' method of 'Math' class.
It's quite easier than 'Random' class itself.