The returned instance must not be shared with other threads or cross a single scope's boundary. For example, a Random acquired within a test method shouldn't be reused for another test case.
There is an overhead connected with getting the Random for a particular context and thread. It is better to cache the Random locally if tight loops with multiple invocations are present or create a derivative local Random for millions of calls like this:
Random random = new Random(random().nextLong()); // tight loop with many invocations.
public static Random ( ) : Random | ||
Résultat | Random |