Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How could random functions be really random?

Introduction

I know I'm going to lose a lot of reputation for this question and I also know it will be flagged as inappropriate but I'm really curious about that so I'm not giving up if there's any chance I'm getting at least an answer.

Question

Today I woke up thinking:

Hei, how could random functions be really random if they are created by an algorithm?

Think about it. How could you create a function that simulates randomness without the concept of random already built in? I began to think:

Hei, I'd take an array of int, then I'd do [thing], then [thing], than [thing] again, then I'd choose only odd numbers... ecc

But it seems more likely a function that make it more confusing to predict what the choose will be rather than real randomness.

Is it possible to create randomness? How are functions that returns random ints (such as rand() in PHP) created? How can they simulate randomness?

like image 965
Shoe Avatar asked Apr 17 '11 16:04

Shoe


2 Answers

Functions that algorithmically produce so-called random numbers are pseudorandom number generators. If you know the seed used to generate the sequence, then the numbers are predictable. The sequence itself is a statistically random distribution but not truly random.

There are true random number generators that typically involve some hardware that samples randomness from the physical world, e.g., radioactivity or acoustic noise. A naive implementation would be to sample hard disk access and mouse movements. See random.org for a real RNG.

Obligatory xkcd strip:

getRandomNumber()...

like image 87
Mark Cidade Avatar answered Sep 29 '22 10:09

Mark Cidade


There's a reason they're called pseudorandom numbers; they're not truly random. From Wikipedia:

A pseudorandom number generator (PRNG), also known as a deterministic random bit generator (DRBG),[1] is an algorithm for generating a sequence of numbers that approximates the properties of random numbers. The sequence is not truly random in that it is completely determined by a relatively small set of initial values, called the PRNG's state.

like image 35
Wayne Avatar answered Sep 29 '22 09:09

Wayne