Week 2 (29/09/2024 - 05/10/2024) Good Random and Texture Generation
- junlachaktophat
- Nov 25, 2024
- 5 min read
Updated: Dec 18, 2024
What is Good Random?
During the second week, the topic of good random and texture generation was discussed. Good random comprises a range of techniques, two of which include pseudo-random and true random.
According to Haahr (2024), pseudo-random systems collect data to produce ambush-generated numbers or values. However, in practice, they collect data from algorithms that adhere to a certain pattern. These algorithms are usually based on predefined steps and starting values. For example, the seed system in Minecraft.

Figure 1: Screenshot from Minecraft (Mojang Studios, 2009), captured by the author on 23 November 2024.
True random on the other hand, is the process of generating random numbers derived from natural sources or unpredictable phenomena, such as radioactive radiation, electronic noise, or quantum uncertainty. Pseudo-randoms have advantages and disadvantages. The following table provides an overview of this:
Advantages | Disadvantages |
Flexibility: Modifiable for repeated testing and for faster computation, unlike true randomness such as hardware noise | Security: Not secure for cryptography |
Predictability: For applications that require traceability, the same sequence can be generated if the same seed value is used. | Reliability: Predictable if the seed and algorithm are known |
Easy to control: Seeds can be set to generate the same sequence of numbers, which is ideal for testing or iterating on processes that require consistency. | Suitability: Not suitable for applications that require true randomness such as lottery draws |
True randoms have advantages and disadvantages. The following table provides an overview of this:
Advantages | Disadvantages |
Complete randomness: The resulting sequence of numbers has no pattern or predictability, making it ideal for applications that require true randomness, such as data encryption. | Resource-intensive: True Random generation requires specialized hardware or complex processes, which can be expensive and time-consuming. |
Ideal for security: True randomness is used in highly secure systems, such as generating encryption keys. | Unrepeatable: If the same results are to be repeated, such as in software testing, True Random may not be suitable. |
Realistic for physics or science simulations: True randomness increases the reliability of research or simulations. | Uncontrollable: The lack of seed configuration capability makes it impossible to control or predict the results. |
For enhanced security and privacy, one example of how true random numbers are generated is Cloudflare’s lava lamp setup. This setup verifies actual numbers using the LavaRnd technique. This technique performs random searches of a lava lamp's wall and the examination of invisible items inside the lamp, to determine the source of entropy such as true random value.

Figure 2:: Lavarand system architecture, adapted from Cloudflare (2017).
Using Good Random in Unity
As part of investigating Good Random, a comparison of the Random.Range() function in Unity and how it differs from the C++ function called rand() was performed. Random.Range() is a C# function in Unity. It is used in the formula of “Random.Range(min, max)”. When using C#, the function returns an int variable using the range (min, max-1). For a float variable, it returns the range (min, max).
Precision and flexibility. For higher precision and safety, it should use a newer function, such as <random> in C++11 and above.

Figure 3: Unity script using Random.Range() to generate random object positions, showcasing its precision compared to C++'s rand().
In contrast, the random function used in C++ is “rand()”. The random number selection for int [0, RAND_MAX] requires a custom range, e.g. rand() % 10 would be a number from 0 to 9. The key difference is Random.Range() supports both int and float but, rand() only int is supported.

Figure 4: C++ code snippet demonstrating the use of rand() for generating random numbers within a custom range, highlighting its limitation to int types.
What is Procedural Texture Generation?
According to itfix.org.uk (2024), Procedural texturing is the process of generating textures using algorithms. Instead of drawing or editing them by hand, textures are generated using computer code that follows a set of rules and parameters to create the desired visual effect.
As mentioned in week 1, World Machine also uses this function. World Machine creates textures, with the main function being Noise functions. According to itfix.org.uk (2024), These functions can create a controllable grayscale noise pattern and similarity at different scales. The noise functions can be combined and manipulated for clouds, water, or land.
Texture Generation in Unity
At the end of the class, there is a task to generate a random texture using Unity's Perlin noise() function in this order: Generate a new random texture every 5 seconds using Perlin Noise. The Perlin Noise scale is incremented every 3 seconds, changing the texture over time. The bump map is updated every 2 seconds to increment the bump map texture.
The function repeats itself using the InvokeRepeating function. InvokeRepeating in Unity is a function that is used to repeatedly call a method, specifying a delay between the first call and a period between subsequent calls. This function is useful if the programer have an event that programer want to happen periodically without writing complicated code.
Source: Created by Juclachak Juntasilp, 2024.
Texture Generation Summary
The reason to use the InvokeRepeating function is to make sure the function is completely random when the project bootstraps, then the programer can keep adding code to the plane object and see the results.
In general, a function in Unity called Perlin noise() is a function that creates a gray noise-like image similar to a noise graph. Developers use this to further develop things, such as adding conditions to Perlin noise() so that it can create terrain based on the generator.
Reference
Cloudflare (2017) Lavarand in production: the nitty-gritty technical details. Available at: https://blog.cloudflare.com/lavarand-in-production-the-nitty-gritty-technical-details/ (Accessed: 05 October 2024).
Cloudflare (2017) Image from: Lavarand in production: the nitty-gritty technical details. Available at: https://blog.cloudflare.com/lavarand-in-production-the-nitty-gritty-technical-details/ (Accessed: 05 October 2024).
National Institute of Standards and Technology (NIST) (no date) Pseudorandom function. Available at: https://csrc.nist.gov/glossary/term/Pseudorandom_function (Accessed: 05 October 2024).
GeeksforGeeks (2021) Pseudo Random Number Generator (PRNG). Available at: https://www.geeksforgeeks.org/pseudo-random-number-generator-prng/ (Accessed: 05 October 2024).
Minecraft (2009) [video game]. Developed by Mojang Studios. Published by Mojang Studios. Screenshot taken by the author (23 November 2024).
Unity Technologies (n.d.) Random.Range. Available at: https://docs.unity3d.com/ScriptReference/Random.Range.html (Accessed: 23 November 2024).
GeeksforGeeks (n.d.) rand() and srand() in C++. Available at: https://www.geeksforgeeks.org/rand-and-srand-in-cpp/ (Accessed: 23 November 2024).
itfix.org.uk (2024) 'Explore the Possibilities With Procedural Texture Generation', Computer Repairs, 25 February. Available at: https://itfix.org.uk/explore-the-possibilities-with-procedural-texture-generation/ (Accessed: 8 October 2024).
Aman (2022) Image from: 'rand() in C++'. Available at: https://www.scaler.com/topics/rand-in-cpp/ (Accessed: 28 September 2024).
Juntasilp, J. (2024) Procedural Random Textures - Google Drive Document. Available at: https://drive.google.com/file/d/1cp-55WTJ-O2ylYBqcB8QGJMJgaARt60M/view?resourcekey (Accessed: 8 October 2024).
Juntasilp, J. (2024) Procedural Random Textures. Available at: https://github.com/jino1113/Procedural-Random-Textures (Accessed: 6 October 2024).
Juntasilp, J. (2024) Procedural Generation Algorithms Demonstration. Available at: https://youtu.be/eypM-5JSTYw (Accessed: 23 November 2024)
Juntasilp, J. (2024) My-CT7120-Procedural-Generation-Algorithms-Project. Available at: https://github.com/jino1113/My-CT7120-Procedural-Generation-Algorithms-Project/tree/My-first-pcg-project (Accessed: 23 November 2024).
Comments