Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Do you necessarily need to create the <code>new Random()</code> inside your <code>random(int i)</code> method? If you are OBLIGED to do it that way, you could use, you could set the seed to the current time, although that is not fail proof, because you could call your <code>numbers.random(10)</code> so fast after the other that it would end up being the same seed. You could try maybe using nanoSeconds (System.nanoTime() I think? And if setSeed only accepts int, multiply it I guess). </p> <p>What I would suggest however, if you are allowed to do so, is to declare your Random <strong>outside</strong> your method. If you instanciate your random variable in, say, your <code>number</code> class constructor, you could set any seed and any time you call your method it would give you a new number. (They will be the same sets of numbers every time you restart your application if you use a constant seed however, you could use time as your seed in this case too). </p> <p>Finally, the last problem could be if you declare several <code>number</code> classes at the same time. They will all have the same random seed and give you the same set of random numbers. If this happens, you can make a <code>static Random</code> in your main class, and call it in your numbers class. This will couple those two classes though, but it would work. Another option would be to send an incrementing value to your <code>number</code> class constructor, for each <code>number</code> you instanciate, and use the value you pass as the seed.</p> <p>The second option should be good for you though, if you are allowed to do it that way.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload