-1

I am looking for one efficent way to generate random numbers using java . I want it to be fast and highly secured. Unfortunately SecureRandom class in java and its method nextBytes() generate highly secured random numbers but this method takes me quite time . I am looking if there is any implementation of a method with the same aim as the one above which has complexity O(1) or worst case O(n).

ENIO MARKU
  • 97
  • 1
  • 1
  • 8

2 Answers2

4

Any RNG or PRNG is going to be O(N) or worse1 to generate N random bits / bytes / whatever. (It is an O(N) operation to copy N bytes / bits ...)

What I think you are really asking is if there are any RNGs or PRNGs that generated numbers fast and / or seed themselves fast. See this Q & A:


1 - Actually, a typical crypto-quality PRNG is O(N). For example, Oracle's SecureRandom uses SHA1 by default, and SHA1 is an O(M) algorithm when hashing an M byte message. This leads to an O(N) PRNG when generating N bytes. Of course, the constant of proportionality for SHA-1 is rather large ... but that is not relevant to the big-O complexity class of the algorithm.

Community
  • 1
  • 1
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
0

You can use Apache commons-math3 to generate random numbers. It has got lots of useful methods for this. See interface "RandomGenerator" and its implementing classes.