Gadget Renesas

Linking Ideas and Electronics

GR Atelier

Title:Using GR-KURUMI to create a Simple Random Number Generator Based on Physical Phenomena

Displayed Name:Michihiro IMAOKA

Using GR-KURUMI to create a Simple Random Number Generator Based on Physical Phenomena

Concept / Overview
A few years ago, NHK broadcast a special program called Scientists Confront Supernatural Phenomena. It was apparently rebroadcast several times; I myself saw the show during this past New Year holiday. I suspect quite a few people saw it. The program highlighted how individuals’ ranging emotions impact random number generators, which are grounded in physical phenomena. The latter half of the program explored an experiment tapping how the emotions of Burning Man festival participants impacted random number generators. Burning Man is an event staged in a desert in one of the American states in which tens of thousands of individuals cohabit in a self-contained environment, cut off from the outside world for one week. The event concludes with the burning of a huge effigy right in front of everyone’s eyes. At that time, participants’ emotions are at their peak, and are said to bias random number generation.

The program content generated a variety of responses, and I encourage individuals to refer to relevant websites exploring this topic. At the same time, as a technical engineer, I also strive to find the true meaning of the program results. To that end, I would like to introduce how to make a random number generator based on physical phenomena. I hope that as many readers as possible will use that information to help verify the truth with their own eyes.

Random numbers from natural phonomena

There are multiple methods for generating random numbers. For example, you can generate random numbers purely using software. This method yields what is called pseudo-random numbers. There are various algorithms available for generating random numbers which I will not get into here, as failure to assign a different initial value each time will cause generation of the same random number sequence. Random number generation can also be accomplished by hardware logic. The diagram shown below is a circuit from an exclusive OR and a shift register.



The randomly generated number is binary. The shift register has multiple stages, with the most significant bit circulating the least significant bit out. The more stages in the shift register, the longer the generated random number sequence. If the clock is continually supplied, the random number sequence will circulate in a fixed length. Random numbers generated in this manner are referred to as M-sequence (maximal length sequence) pseudo-random numbers. The point at which the exclusive OR factors in determines the M-sequence random numbers. Several such points in the shift register number have already been discovered. In order to generate random numbers, the initial shift register value must be 1 in at least one instance. 

Now let us put that aside and examine random number generation from physical phenomena. The most familiar example of this might be tossing dice. However, this would be an exhausting way for individuals to generate many random number sequences. Even if you could create a machine to retrieve and toss dice (which in itself would be exhausting), the dice would age, causing deviations in face-up results. As I wrote in the Introduction, my purpose was to create as simple a device as possible, so that would seem to rule out the above idea. Instead, I would like to begin by using electrical transistors—priced at \10 or less each—to create a source for generating random numbers.



First of all, let us listen to white noise



The transistor used as a generation source for random numbers in this project was a 2SC1815L-GR. It is one of the more least-expensive and easily-obtainable transistors. An online shop with a branch in Akihabara prices them at about 20 for 100 yen.




The transistor appears in circuit diagrams as shown here.





B represents what is known as the base. The directional arrow indicates the emitter (E). At the opposite end is the collector (C). The name “emitter” reflects its function as the pole emitting the electron. Similarly, the collector’s name stems from its role in collecting the emitted electron. When the transistor was first invented, it was manufactured with the collector and emitter electrodes attached above the base, so unlike “emitter” and “collector,” the term “base” does not derive from its function. Transistor manufacturing is completely different from what it was in the early days, but the term remains.






A transistor consists of P-type and N-type semiconductors. The 2SC1815L-GR is an NPN-type transistor, which has a P-type semiconductor sandwiched between NPN configuration.

Collector and emitter pins are attached at either end of the N-type semiconductors. The base electrode emerges from the P-type semiconductor sandwiched between the N-type semiconductors. When the P-type and N-type semiconductors are joined in this manner, an interesting property manifests itself. The electrical current flows from the N-type to the P-type, but the current does not flow in the reverse direction (from the P-type to the N-type).


This table shows the maximum rating of the 2SC1815 used in this project. Suppling voltage higher than these levels may cause irreversible breakage of the transistor. I would like you to pay particular attention to the emitter-base voltage shown in the above table It indicates that no more than 5V should be directed from the emitter to the base. This is an extremely low value compared to the voltage passing between other terminals. When this value is exceeded, a strong current will suddenly flow in what is known as a breakdown. Voltage triggering a breakdown is known as breakdown voltage.


This value is shown as VEBO in the table, and can cause avalanche breakdown. Kindly refer to the reference material for further details. Intentional creation of this avalanche breakdown generates white noise, a source of random numbers. Applying a negative voltage to an N-type, and a positive voltage to a P-type, is known as applying a reverse bias, but when transistors are typically used as amplifiers or switching devices, the reverse bias is not applied.



The diagram shows the circuit of a transistor generating white noise. Power is supplied by a 9V 006P battery. Voltage is applied between the emitter and the base, generating an avalanche phenomenon. The maximum rating for VEBO is 5V, but in actuality, the avalanche phenomenon is generated with well over 8V. I think that is because the transistor was designed with plenty of allowance. If you generate a major avalanche breakdown, it will generate a large current flow between the base and the emitter which will damage the transmitter, so a 1M-Ohm resistor was introduced This provides enough resistance to prevent damage to the transistor from an avalanche phenomenon.



The diagram shows the breadboard mounting. You can hear the white noise by connecting a crystal ear piece (see photo) to the emitter and base configuration shown above, or to the power supply GND. The noise is rather small, but it resembles the buzz you hear on FM radio when you have dialed past a station. You are hearing white noise caused by a transistor avalanche phenomenon. The noise is from an electron speeding up due to an electric field and overcoming the p-n junction wall it normally cannot pass. Think of this phenomenon, this noise from each individual electron, as the sound of each salmon or sweet fish as it swims over floodgates and on upstream.




Use of a crystal ear piece is critical, as normal earphones utilize electromagnetic coils, with a resistance value of a few dozen ohms. If you connect a general-use earphone to the base and emitter, the voltage between the two will drop, halting the avalanche phenomenon. Such resistance is extremely high with crystal ear piece. Moreover, most crystal ear pieces are actually ceramic earphones incorporating ceramic as a raw material. For our purposes, either crystal or ceramic will do.


Incorporating white noise with KURUMI ADC



So let’s try using KURUMI to generate white noise between the transistor’s emitter and base. The circuit is what generates the white noise, as we discussed before. The transistor base (output from the circuit) is connected to KURUMI analog input 0. The FTDI Basic Programmer to the left of KURUMI is use to write the prepared program to KURUMI itself, and it is also used to send the value of the white noise retrieved by by the AD converter to the PC.



This diagram shows the circuit described here, mounted onto the breadboard.


The program is written to KURUMI as follows:
1: void setup() 
2: { 
3: Serial.begin(9600); 
4: }
5: void loop() 
6: { 
7: int sensorReading = analogRead(A0); 
8: delay(10);
9: Serial.println(sensorReading);
10: }

The serial interface is set in line 3. This project used 9600bps. This code is described in the setup function, and implemented only once after KURUMI is reset. 
Line 5 contains the loop function codes - the codes that will be repeated in order after the setup function is executed.
Line 7 acquires the value from analog input AO, and stores it in the integer type sensorRading. The delay function in line 8 creates a 10-millisecond wait. This enables adjustment of the number of data to be sent to the PC after the AD converter value is stabilized.
Line 9 sends the integer-type value acquired by the AD converter via serial interface to the PC at the baud rate set in line 3. A line break is added after sending the value acquired by the AD converter labeled with the “ln” of “Serial.println()”. The integer-type value is converted to a decimal character string and then transmitted.

Now let’s connect the board via USB to a PC and survey the value of random numbers. The PC recognizes the FTDI BASIC PROGRAMMER, which is used to program KURUMI, as a virtual serial port. The value of the white noise can be retrieved by reading the serial port. Since I am using a Windows environment, I used well-known TeraTerm as a terminal emulator. The virtual serial port connected to FTDI was set in at start up. The baud rate was set to 9600BPS. All other settings remained as default values.

As you scroll down the TeraTerm screen, lots of seemingly meaningless values continue to appear. Usually, ADC resolution is 10 bits with an upper limit of 1024, with very minor changes in values. If the white noise generated by the transistor is input directly into the ADC, there may not be enough gain. Or, impedence at ADC input may cause a voltage drop. Regardless of which is the cause, we need to consider another method.




Resolving insufficient gain with an operational amplifier




Insufficient gain should be resolved by amplifying the input signal. There are many ways to various filters, comparators, and signal generators. The op-amp offers a neat package integrating circuitry comprised of simple elements such as a transistor and FET. As the name infers, op-amps enable various operations, such as signal conditioning, mathematical operations, and filtering. Before digital computers were mainstreamed, op-amps were used as operational elements in analog computers. The LM358N op-amp used in this project.





The LM358N was originally developed by National Semiconductor, but a variety of semiconductor companies worldwide have become second source manufacturers, making this one of the most popular low-priced op-amps available. Electronics parts shops also have a variety of LM358s made by various manufacturers, but any of them would work fine for this project. It would be fine to purchase the one offered at the most reasonable price. An online retailer with a branch in Akihabara sells them at a price somewhere around 5 for \100. Please be sure to get the DIP type package, as shown in the diagram. This will allow direct insertion onto the breadboard. There are two op-amps in the package, as the diagram illustrates.






The diagram shows how to use the op-amps.
The circuit shown here uses a single power supply. Op-amps normally use two power supplies—positive and negative. However, the LM358N enables a single-source circuit. Input is applied to the minus input (pin 2) through resistor R2. Output is through pin 1. Output is returned to the minus input through resistor R3. The diagram depicts an inverting (negative) amplifier, which outputs an inverted signal in response to the input signal. When a sine wave is input, the amplifier will output a signal that is 180°”out-of-phase” with the input signal. Of course you could also configure a non-inverting circuit, but an inverting amplifier normally offers better performance.


Amplification efficiency depends on resistors R3/R2. The amplification efficiency of the circuit in the diagram is 33,000/100 = 330. R2 input resistance should ideally be a bit greater, but I ended up with this value because I only had a 100-ohm resistor on hand as I was on a business trip. Normally, at least 1K-ohm resistance is recommended. R4 regulates voltage applied to the op-amp’s positive input. Normally, a fixed resistor divides the voltage to ensure that half of the power voltage is applied, but, in this project, variable resistance was used for adjustment because bias voltage is applied to the input signal.





This diagram shows the circuit that inputs the signal amplified by the op-amp into the GR-KURUMI ADC. The LM358N includes two op-amps in a single package, but only one was used in this project. The other is left over; whenever there is an unused op-amp, please be sure to apply differing voltage to the two inputs and fix the outputs. If neither input is connected or if the same voltage is applied, the output value will not be fixed and may generate noise. Please use these precautionary measures to avoid noise.



This diagram shows the above circuit mounted on a breadboard.





The diagram depicts the op-amp pin assignments. The surface of the op-amp shows a crescent-shaped depression; make sure the depression is facing upward and the pin on the left becomes pin 1. Pin numbers 1 through 8 are as shown on the diagram. In the breadboard diagram, the side of the op-amp with the depression faces left.
Connect earphones between pin number 1, which represents the LM358N output, and GND to adjust variable resistance and hear maximum possible white noise.



The following graph depicts the terminal emulator buffer copied into a spreadsheet program and shown in graph form.
Use of the op-amp ensures the signal is sufficiently amplified. We can confirm that there is no saturation on either the plus or minus side.




I applied a reverse bias between the base and emitter of an electrical transistor to generate white noise by intentionally creating an avalanche phenomenon. I used the GR-KURUMI ADC to quantize the noise and obtain corresponding values via a PC. My next project will focus on investigating whether or not the white noise was truly random numbers. Look forward to some new results!

■ Reference Materials Breakdown phenomenon:

Topics for future research
■ Randomness testing
■ Generating high voltage with a microprocessor
■ Random number generation using the tunnel effect
■ Delving further into the uses of operational amplifiers

Renesas MVP infomation Michihiro IMAOKA

Owner/CEO, Imaoka Engineering
Michihiro Imaoka was a full-time programmer until about 15 years ago. Basically, he wrote code day in and day out, coming up for air only occasionally. He is particularly adept at FPGA coding and SMD soldering. Lately, he transitioned into authoring technical materials. Now he sits at his desk writing from dawn to dusk.

Mr. Imaoka is located in Matsuyama, Ehime Prefecture, where he:
- Focuses on contract-based work, developing embedded systems
- Continues to write manuscripts
- Lectures at “security camps” and other IT events
- Provides hardware startup support
- Remains active in the open source community