Bob
Bob

Reputation: 10805

Groovy/Java generate long values (min, max range)

I have to generate one million numbers of 64-bi signed integers. How can I pick random long value in Long.min() and Long.max() range, i.e from 0 to 2^64 - 1?

Upvotes: 0

Views: 895

Answers (1)

Opal
Opal

Reputation: 84824

Try:

new java.util.Random().nextLong()

There's no need to specify package java.util when it comes to groovy.

To generate the numbers:

new Random().with { (1..1000000).collect { nextLong()} }

Upvotes: 2

Related Questions