Introduction: Over Engineered True Random Value Generator

About: Hi!! I am Aditya Patil, robotics enthusiast and a hardware designer developer, skilled with stuffing anything into small space and loves to make tiny robots.

Random numbers are often used in daily for example in encryption, gambling, gaming and much more. These numbers are generated by computers using complex algorithm but it can be predicated if we know the seed value and the algorithm.

So this is my attempt to create over engineered and as far as possible most random number generator.

Step 1: The Idea

If not algorithms then what should be used to create random. This universe is the most unpredictable thing, then why not use its elements to generate random numbers.

Elements such as pressure, humidity, temperature, vapour pressure and many more. Sensors are available to measure such quantities but we will use ones which don’t need modules to measure.

Basic idea will be to sense a element -> produce a number correspondingly -> then pick a number from a number pool (which also be random one) do some operations over it which will depends on new number produced from element (can you guess what will be a number pool before it is introduced in step 7) and then display it.

Step 2: Supplies

Zero PCB – 18 x 20 holes

Arduino uno x 1

Male headers – 3 x 1, 1 x 1, 1 x 6

Single strand wire – about 50cm

LDR x 1

2.2K x 1

Electret microphone x 1

4.7K x 1

0.47uF x 1

Push button x 1

OLED display module 128 x 32(pixels) x 1

Female headers – 4 x 1

Solder wire

Soldering iron

Step 3: Introducing 1st Element

What can be better than a floating pin which picks up stray electromagnetic waves in air?

We just have to attach a wire to an analog pin of uno.

Pin A2 is the floating pin.

First male headers were soldered on PCB.

Headers have been modified, black spacers are pushed down so that metal pins come up and more length can be used for inserting into female headers of uno.

This has to be done because the PCB does not has solder pads on both sides.

I have attached a PCB layout in case you want recreate this project.

Points having distance between them of 5mm on graph paper represent adjacent holes on zero PCB.

Step 4: Introducing 2nd Element

Next event I would like to introduce is - intensity of light.

Simplest component to generate values using it is a LDR.

Resistance of LDR changes based on intensity of light falling on its surface.

If we create a voltage divider using fixed resistor and LDR then voltage between these two will change which can be detected using another analog pin of Arduino Uno.

I have chosen 2.2k resistor because it is between maximum and minimum values LDR can produce.

One side of LDR is connected to +ve and other to resistor and other side of resistor is connected to ground.

Pin A0 of uno is connected to where LDR and resistor are connected

Step 5: Introducing 3rd Element

Using an elecret microphone to pick up ambient noises in surrounding would be a good choice.

The mic doesn’t come with any header or extended pins so that we can solder it on PCB but instead has solder pads.

Before adding header to the mic identification of solder pad is necessary, if you closely observe the pads you can see that one of the pad is connected to metal casing of mic using solder masked wires, that one is ground pin and other will be positive.

Then headers were soldered in a little tiled manner to the electrets microphone.

Appropriate components were chosen like 4.7K resistor to limit current to min and 0.47uF to filter out the DC section of signal.

Then all components were soldered on the PCB according to the layout.

Pin A1 will pick up the ambient sounds.

Step 6: Putting All Together

The last step in putting things all together will be adding a display module to show the random number generated and to add a button to trigger or say to tell the system that user wants a random number.

I have used an OLED 128 x 32 display module and push button.

Button is directly soldered on PCB but display module is attached using male female header combination so that it can be removed whenever required.

PCB is so designed that it fits over Arduino Uno like a shield.

Step 7: Pi Bank

I could have simply taken values from pins and present it as this even keeps the numbers generated to be random but there is no fun and very straight forward.

So to give a little twist why no use the digits of pi which are completely random and never ending.

Being the digits completely random there are few methods using which we can find the digits like the Gregory-Leibniz series: pi/4 = 1-1/3 + 1/5 – 1/7 + 1/9 - ....

But there is no use in doing the work which has already been done.

We can get all the digits of pi here but I will only use up to 512 and why I have done this you will understand in next step.

Step 8: The Code

Now is the time to create crazy enough logic to work upon these numbers.

First an array will be created where all the digits of pi will be stored sequentially.

Now you might wonder why only 512 digits are used this is because of low memory in Arduino Uno.

Arduino Uno has about 2KB of memory for keeping variables.

So if we use 1023 corresponding to ADC of Uno then half of the ram will be consumed by the array.

Array and remaining variables consume about 75 % of the ram which leads to astability of the code so size of array has to be reduced.

Reducing to half works pretty fine.

After creation of array it takes values from elements, reduces that values using map function, extracts numbers from pi bank according to received values form elements and then works upon them further.

Flowchart shows very well what the code does.

what interesting part is that the code is so setup that when button is pressed it generates random number every 100ms and displays it and when you release the button it stop at one particular number so kind of gives a rattling effect.

Step 9: Done!

And we done here each time button is press it generates a random and displays it on OLED display module.

Step 10: What Next?

As an improvement more elements can be added and more crazy logic can be created.