Pseudo-Random Numbers in C

Pseudo-random numbers in C

Pseudo-random numbers in C:

Introduction:

In Ancient Greek, the adjective:

ψευδής[1].

or, when transliterated:

‘pseudḗs’

means:

‘lying,’ ‘false,’ ‘fictitious,’ ‘sham’[2].

.

A classical computer is a deterministic machine, and, in and of itself, cannot generate a truly random number.  A classical computer, in and of itself, can only generate a pseudo-random number.[3].

A pseudo-random number is not a true random number – its having been generated through a deterministic process – however it is considered, from a human perspective, random enough for most purposes.

Body:

In C, we use the:

rand()

function so as to generate a pseudo-random integer.  Prior to our invoking the:

rand()

function, though, we must first:

include

the:

stdlib.h

header file.

Thus:

#include <stdlib.h>

.

The code needed so as to compile a simple pseudo-random number generator is as follows:


    Snippet 1:  The code needed so as to compile a simple pseudo-random number generator.

The code, as found in Snippet 1, when compiled into an executable, outputs the following program:



    Figure 1:  The program outputted should the code in Snippet 1 be compiled and executed.

As we may observe, the program as depicted in Figure 1: produces the pseudo-random integers:

41

and:

18467

.

Conclusion:

Should one know how to generate pseudo-random numbers in the C programming language, then he/she knows how to generate pseudo-random numbers in C# and C++, which are two languages that are employed so as to code modern videogames in the UnityTM and UnrealTM engines/IDEs, respectively.

I once heard it said that it is the random-number generator that makes videogames fun, as it can make the enemies and hazards that the player must face unpredictable.  Being able to generate pseudo-random numbers in C-derived languages is a must-have skill for a professional game-developer.



[1].  ψευδής, ψευδής, ψευδές or ‘pseudḗs, pseudḗs, pseudés,’ 1st-and-2nd-declension adjective.

[2].  James Morwood, John Taylor (ed.s)  Oxford University Press.  Pocket Oxford Classical Greek Dictionary  . Oxford.  2002.  p.  352

[3]. For a classical computer to obtain a true random number, it must go outside of itself. The website, random.org obtains true random numbers by deriving them from the measurement of atmospheric noise.

Comments

Popular posts from this blog

The Increment and Decrement Operators in C:

An Introduction to Modern Geometry: The Directed Line Segment