Andy’s Neural Works

A wise folly can lead to great things!


An Exploration of Random Numbers – Part 4: Conclusion with an Experiment

Published by

on

Published on: January 19, 2024

Author: Andrew Della Vecchia

It is now time to conclude the series on random number exploration. This has been quite a challenge to dive this deep. For the final part of the series, it would be good to summarize. I also have an interesting experiment to try toward the end but first, let’s review.

Random Number Generator (RNG) Definition Revisited

The initial view of a RNG we dove into was pretty simple. RNGs are an algorithm that generate a sequence of numbers that should be unpredictable from previous history. We went into how there really is no “True” RNG (TRNG) with a deterministic system. As a result, we do have pseudo-RNGs (PRNGs).

One concept I want to put out for thought is the use of PRNGs for simulations. A more specific example of this is with the world of video games.

A game developer can implement a very clever algorithm called Wave Function Collapse1 to generate artificial worlds. This algorithm has roots in quantum mechanics2 and the end goal is to have procedural developed game levels (*note: do not confuse the implementation from physics). In other words, the game designs its own levels rather than having pre-rendered worlds drawn by hand.

Where this has a connection to this series’ topic is in how it uses randomness in an elegant manner. I will be very basic here as there is much going on. The designer builds a core tile image set of pathways he might want to use for a level. Think of an image of a portion of train track that has a crossing to it or a pathway through a forest. This tile is used as a template and creates an organized map. “Organized” being the key word in that statement.

The process wouldn’t be too useful if the pathways were completely random. In that case, the map would have many dead-ends and roads that go nowhere. It would not make sense. Still, it would be boring if the generated map would be the same no matter what the state. This is where the randomness happens to create a more diverse design. Cookie-cutter design is rarely good for excitement and disorganization can lead to frustration.

I put references below to some good explanations with code examples. Give them a try and maybe it will spark some thoughts for your own experiments3. I found a simple example using some C found on Rosetta Code4.

At a high level, the code creates a map out of a set of 5 tiles seemingly chosen at random. Each tile is defined in a 3×3 array of 1’s and 0’s. A value of 1 represents a possible solid part of the path and 0 = blank or non-usable part of the pathway. For example, tile 1 is defined as:

{0, 0, 0},
{0, 0, 0},
{0, 0, 0}

Since this is defined as all 0’s then there no pathways in this tile. Compare this to the next tile which is:

{0, 0, 0},
{1, 1, 1},
{0, 1, 0}

This results in a tile (built with #’s) that looks like:

# # #
  #

The rest of the tiles are defined to be other possibilities. Once run, the algorithm analyzes factors such as information entropy5 to figure out where to layout the pathway. The end result is a set of pathways that seems like it is organized.

Example Result of Generated Pathways

If you run it several times, you will get different pathways. This is due to a randomization process used in the algorithm. What starts out as something that could be completely disorganized gets well arranged to a usable map. I consider this a rather clever use of random number generation.

Does this redefine a RNG? No, but it is an example of how a RNG can be used for more than building an unpredictable sequence of numbers. That is if anything is unpredictable. When it comes to computer science, it is essential to remember that a random sequence is unpredictable until it is proven predictable.

Quality Measures Exist

This leads us to remember how diverse RNG algorithms can be. There are some analysis techniques being used alongside numerous efforts to create a standard set of tools for quality measures. I will remind everyone here that there are no true standards but plenty of good, scientific tests to run. Be aware to not force a solution out of an intellectual exercise. Define the requirements needed for the RNG first. Then, run tests and analyze the results. Strive to always pick the tool that fits the need. This might take more effort than originally thought but will serve you well in the long run.

Predictable but Ease is Not Guaranteed 

Along with quality measures, remember that these are PRNGs. This means that there are certain expectations that the sequences will have some level of predictability. Any perceived image ease should be taken with a grain of salt. The only prediction method that would have any chance of ease requires having awareness of the algorithm and its internals. This will enable someone to design an exploit based on the inner workings of the known PRNG. 

Outside of some insider knowledge, brute force, or a good guess, what else can we try? How about we grill an AI again? This should be fun.

One more experiment – Let’s Grill the AI Again

I picked Google’s latest version of Bard6 as the AI to grill. I believe this is now using Project Gemini7. As a side note, I am impressed at how fast Google has improved their Generative AI Experience. In essence, I see these as great machines that can summarize information known from Internet sources and present it all in a clever manner. Maybe it will have a bit of organized randomness added someday.

I took our previously generated sequence of numbers from the Mersenne Twister as the source. Interesting that it could handle many numbers. That is encouraging to see efforts to accommodate large sequences.

Now for the hard question. Can it determine the algorithm given only the sequence of numbers?

Question:

What algorithm created this sequence?

Answer:

===

I’m unable to determine definitively what algorithm created the sequence based on the numbers alone. However, I can offer some insights and suggest potential algorithms that might have been used:

Observations:

  • Values between 0 and 1: All the numbers in the sequence fall between 0 and 1, suggesting they might represent probabilities, normalized values, or outputs from a function that produces values within this range.
  • Apparent randomness: There doesn’t seem to be an immediately obvious pattern or structure to the sequence, indicating it might have been generated by a random or pseudorandom process.
  • Groupings and spacing: The numbers are sometimes grouped together (e.g., 0.81093 0.7321), while other times they are spaced individually. This could be due to formatting or might hint at some underlying structure.

Potential Algorithms:

  • Pseudorandom number generators (PRNGs): These algorithms produce sequences of numbers that appear random but are actually deterministically generated from a seed value. Common PRNGs include the Mersenne Twister, Linear Congruential Generator, and more.
  • Statistical sampling algorithms: These algorithms are used to generate random samples from probability distributions. They might have been used to produce this sequence if it represents a sample from a specific distribution.
  • Fractal algorithms: Fractals are mathematical structures that exhibit self-similarity at different scales. Some fractal algorithms can generate sequences of numbers that appear random but have underlying patterns.
  • Neural networks: Neural networks, especially those used for generative tasks, can produce sequences of numbers that resemble real-world data. However, the output often has some structure or patterns that might not be present in this sequence.

Need for Additional Information:

To narrow down the possibilities, I’d need more context about the origin of the sequence or its intended use. Here are some relevant questions:

  • Where did you obtain this sequence?
  • Is there any information about the algorithm or process that generated it?
  • What is the purpose of the sequence? What is it supposed to represent?
  • Are there any constraints or properties that the algorithm should satisfy?

With more information, I might be able to provide a more accurate assessment of the algorithm that generated the sequence.

===

Wow! The AI could not do it but it is basically saying “I don’t know.” One aspect of its response is that it gave some possibilities as to why it could not answer the question.

Let’s grill it a bit more in a direct manner. Ask to see if it can predict some more numbers after the given sequence.

Statement:

predict the next 100 numbers in the sequence

Response:

===

Unfortunately, I cannot predict the next 100 numbers in the sequence without additional information about its origin and underlying structure.

===

A short answer but good! It was not tricked into generating nonsense!

We already know from our previous experiments that if you know the algorithm, you can reverse engineer the internal state (at least for Mersenne Twister).

The Future of RNGs

Once again, are there really any TRNGs? A physicist will point to a quantum computer. This is probably the leading candidate yet only a few really have pushed that limit. More must be done to back this up for daily, practical use. In the meantime, think about what can be accomplished if a quantum computing is not an available.

We always hear about the unpredictable nature of human emotions. Maybe if a sentiment analysis were done on a website containing comments (YouTube Comments would certainly be an interesting subject to study), maybe a metric could be built and used as a seed. It would be a cool endeavor to look for patterns in human sentiment as a whole.

Since this is getting far into the what-ifs, I believe it’s time to conclude the series. Keep in mind, I have plenty of experiments on this topic that just might show up in a future article.

Closing Thoughts

To close this series out, I will put a flag in the ground and say that more needs to be done to grow randomness from its current state. Even my simple set of experiments showed gaps that currently exist. There are plenty of unknowns still out in existence which demand further exploration. What I’m not sure of is if it’s possible to find a 100% unpredictable source in a physical world bound by physical rules. Maybe you will be the one who proves true randomness or maybe prove that everything is predictable no matter how we try. In any random view, I wish you good hunting.

Have a great day!

References

[1] Maxim Gumin. Wave Function Algorithm. July 21, 2022. Retrieved from: https://github.com/mxgmn/WaveFunctionCollapse

[2] LibreTexts Physics. Schrodinger’s Equation and Wavefunction Collapse. Retrieved from: https://phys.libretexts.org/Bookshelves/Quantum_Mechanics/Introductory_Quantum_Mechanics_(Fitzpatrick)/02:_Wave-Particle_Duality/2.12:_Schrodinger’s_Equation_and_Wavefunction_Collapse

[3] The Coding Train. #171 — Wave Function Collapse. Retrieved from: https://thecodingtrain.com/challenges/171-wave-function-collapse

[4] Wave function collapse. Retrieved from: https://rosettacode.org/wiki/Wave_function_collapse

[5] Jason Brownlee. A Gentle Introduction to Information Entropy. July 13, 2020. Retrieved from: https://machinelearningmastery.com/what-is-information-entropy/

[6] Google. Bard. Retrieved from: https://bard.google.com/chat

[7] Google. Introducing Gemini: our largest and most capable AI model. Retrieved from: https://blog.google/technology/ai/google-gemini-ai/