1

I apologize in advance as I am not very experienced with any formal notion of randomness.

The title says most of it: I want to generate a random integer within a reasonable time, where every integer can appear, whether with equal frequency or not isn't important. As an add on, computer memory is not an issue, as even with infinite memory space to store these generated numbers it isn't obvious how one could do this. I haven't made any progress in actually figuring out a proper algorithm but here are my observations.

If you can generate any real number randomly then you could use functions like the floor function to generate any integer. If you could randomly generate any real number between any interval $[a,b]$, then you could use asymptotic functions like $\tan$ to generate any real number.

In general if I have a set S which has a larger or equal cardinality to the integers, and I can randomly generate an element within S, then I can randomly generate any integer by mapping members of S onto the integers.

I know that there are sequences, such as the prime gap sequence, which are random and contain arbitrarily large integers, but are not computable easily.

However that is about it with regards to what I can think of. I would not be surprised if there was no easy solution to the problem, but if anyone has a reason as to why this is not possible I would like to hear as well.

person
  • 1,373
  • Well, if the distribution is all the same to you, and you want a simple algorithm working in essentially any programming language, why don't you take the equivalent of $floor(1/random())$, where $random()$ generates something in $(0,1)$? –  Dec 27 '20 at 18:53
  • @ProfessorVector Add a coin flip for the sign of the integer and that is golden. (And modify it so that $0$ is actually possible.) – Rushabh Mehta Dec 27 '20 at 18:54
  • For any programing language, there is a limit to how precise the numbers in the RNG can be. I am interested in an algorithm that can generate any number, no matter how precise. I understand that this may be computationally near impossible, but I still want to see if anyone can come up with a reason as to why this is impossible. – person Dec 27 '20 at 18:56
  • @person By that metric, it is impossible. There are only finitely many numbers up to a certain precision expressable, and hence, you can only distinguish between finitely many elements. – Rushabh Mehta Dec 27 '20 at 18:57
  • An early pseudo random number generator (which satisfied certain Knuth spectral test criteria) was ran_2 = fractional part of (9821 * ran_1 + 0.211327). The random number was therefore, 0 <= ran < 1. Then, let's say you wanted the nth card in a deck, integer part of (52 * ran + 1), yielded 1, 2, 3, ..., 52. This can be applied to any pseudo random number generator. Alternatively, you could use a 10-sided die (0-9) and create any size number. – Jim Clark Dec 27 '20 at 19:00
  • @Don Thousand, I think that I should add that computer memory is not an issue, because even if one had infinite storage, it isn't trivial that one could generate any random number. – person Dec 27 '20 at 19:05
  • @Jim Clark, if possible, use mathJax, as I think you're onto something but it's a bit difficult to understand what you are conveying. I understood your comment about the dice to be something similar to rolling a dice repeatedly to generate the decimal representation of a random integer. However that would require you to roll the dice infinitely many times. – person Dec 27 '20 at 19:09
  • 1
    You can seed the random pseudo number generator by picking a random fractional number as its seed. Using a random analog input is another way to get random data. Read the floating point value (voltage) from a light sensor, sound sensor, thermal sensor, etc, and convert it to a decimal value as a seed for a pseudo random sequence, or take, for example, the integer part of (100,000 times the fractional value of the voltage) as your random value. – Jim Clark Dec 27 '20 at 19:13
  • @JimClark, can you please provide an example of such a pseudo random generator? – person Dec 27 '20 at 19:23
  • Actually, it is impossible to choose a "random integer". And if we could, we would have a number larger in absolute value than we could express with probability $1$. We can however choose a very large interval (Let's say $[-10^{10^6},10^{10^6}]$) and choose a random number in this range. – Peter Dec 28 '20 at 18:46

1 Answers1

0

The arbitrary size has no meaning since the computation cannot halt!

Consider that you toss a coin for every bit of the random integer, then you can see that the coin tossing is never-ending.

One should be careful when playing with the arbitrary size. Mathematically you can say that let $x$ be a random integer, i.e. $x \stackrel{R}{\leftarrow} \mathbb Z$ , however, when you try to find a value of this you will face the generation of it. If you want a uniform random integer then obviously it will fail!

Now assume that you have a limit like $0\color{red}{<} x \leq 2^L$ then you can use LFSR's to generate random numbers in the range. If an LFSR with size $L$ is maximal then it is periodic and it has a period of $2^L-1$. In this period it visits all possible $L$-bit numbers except the all-zero state. You can get a seed from the time and start using it.

Note that LFSR is far from away from being a Cryptographically Secure Random Pseudo Generator (CSPRNG). Having just $2L$ bit output from the LFSR is enough to determine the next bits due to the Berlakamp-Massay algorithm - and actually, Gaussian elimination is enough, however, BM is a lot faster-.

kelalaka
  • 1,637