Victor Fong
Victor Fong

Reputation: 1

True Random number of an integer through a byte generator (BlueRand)

I'm trying to create a Java application that receives a string and uses that string to determine how many integers should be randomly selected from a range from 1 - x where x is an integer value. I understand that "True" random generation is difficult/impossible using modern computing technology, but a github repository gained my interest that uses jpeg images as a source of random number generation (https://github.com/prgpascal/bluerand).

The generator seems to create a random amount of bytes, however, and so I was wondering if any of you may have any indication of how one might use this to somehow generate integers within a range.

Of course, if any of you know any other generators without a quota limit, be it from a website with an api or a library that works on a local computer that can do this task and I've missed it, I would be happy to learn of it and move my attention to it!

Thank you for your time.

Upvotes: -4

Views: 134

Answers (1)

Stephen C
Stephen C

Reputation: 719436

Here is one way to turn an array of "random" bytes into a random number in a range 0 ... N - 1:

  1. Take the first 8 bytes, and convert them into a long; for example

      l = (b[0] & 0xffL) | (b[1] & 0xffL << 8 ) | 
          (b[2] & 0xffL << 16 ) | ... (b[7] & 0xffL << 56 );
    
  2. Calculate the number as

      n = Math.floorMod(l, N);
    

If any of you know any other generators without a quota limit, be it from a website ...

  1. Asking about external resources is off-topic.

  2. It is a bad idea to make an application dependent on a website that might go down, might go away, might cost someone network changes, etc.

  3. It is a bad idea to get random numbers from an untrusted source:

    • they may be recording them
    • the numbers may actually not be really random (despite what they say)
    • the numbers may be biased (accidentally, deliberately).

Also, note that the "truly" random numbers you get from images via the BlueRand library are not random at all .... unless you have a good source of random images; e.g. a live feed if pictures of something with motion.

Upvotes: 1

Related Questions