The TrueRNG Hardware Random Number Generator is a USB device sold by ubld.it that generates true random numbers using the avalanche effect in a semiconductor junction. This is the first Matlab interface for the device shared on the File Exchange. Usage is very similar to the Matlab rand() function, but also permits use of an options structure to improve operation speed.
Example 0: Generate a 32-bit random number from the uniform distribution
on the interval [0, 1].
r = truerng()
Example 1: Generate 100 values from the uniform distribution on the
interval [a, b].
a = -10;
b = 10;
r = a + (b-a).*truerng(100,1)
Example 2: Generate a 2 x 1 array of 8-bit random numbers. (TrueRNG
device is known to be available at Windows COM port 5.)
opts.COMname = 'COM5'; % specify COM port
opts.precision = 8; % specify precision
opts.display = false; % turn off messages
r = truerng(2,1,opts)
Note for Linux users: Please follow the instructions provided by
ubld.it to set up the udev rules for TrueRNG.
The first time TRUERNG runs, it will add a line to your java.opts file and
ask you to restart Matlab to reboot. Matlab may require superuser
priviledges to edit the java.opts file and access the TrueRNG serial port,
i.e. run Matlab using "sudo matlab" from the terminal.
Note for Windows users: You must first follow the instructions provided by
ubld.it to set up the driver. Operation is fastest when specifying the COM port
name corresponding with the TrueRNG device using opts.COMname. The port name
(e.g. COM5) can be found in the Windows Device Manager under "Ports".
See Example 2 above.
TRUERNG Uniformly distributed true random numbers from ubld.it TrueRNG device.
R = TRUERNG(N) returns an N-by-N matrix containing true random values drawn
from the standard uniform distribution on the open interval(0,1).
TRUERNG(M,N) or TRUERNG([M,N]) returns an M-by-N matrix.
TRUERNG(M,N,P,...) or TRUERNG([M,N,P,...]) returns an M-by-N-by-P-by-... array.
TRUERNG returns a scalar. TRUERNG(SIZE(A)) returns an array the same size as A.
Note: The size inputs M, N, P, ... must be positive integers.
TRUERNG also accepts an (optional) options structure, e.g.
TRUERNG(...,opts), with the following fields:
- opts.display is a boolean value that controls whether to output
status messages. The default is true (on).
- opts.bypasschecks is a boolean value that controls whether to perform
some error checking. The default is false (perform checks). Turn
this off to reduce execution time.
- opts.COMname is the (string) name of the serial port corresponding with
the TrueRNG device, e.g. opts.COMname = 'COM5'. This option is unnecessary
for Linux machines if the udev rules provided by ubld.it have been
installed correctly. For Windows machines, execution is fastest when
this option is used, but it is not required. The name of the serial port
corresponding with the TrueRNG device can be found in the Windows
Device Manager under "Ports" and is also printed in the command window
when opts.display == true (default).
- opts.precision is the precision of each random number. Valid options
are 8, 16, and 32 (bit). The default is 32.
- opts.cleanup is a boolean value that controls whether to close the
COM port after execution. The default is false (do not close), which
reduces execution time of subsequent calls to the function.
- opts.bufferN is the COM port input buffer size. The default is set
such that the buffer is filled in approximately 1s, assuming nominal
device operation at ~49 kBps. This should not need to be changed
unless your machine will not support that buffer size.
Defaults are used for any option field not created or assigned empty.
This function is not designed to support parallel computing.
Tested in Matlab 2012a and 2014a, Windows 8.
Tested in Matlab 2012a, Ubuntu.
IDSerialComs from Benjamin Avants via Matlab Central File Exchange
included with written permission of author
Matt (2019). TrueRNG Hardware Random Number Generator Interface / Driver (https://www.mathworks.com/matlabcentral/fileexchange/46168-truerng-hardware-random-number-generator-interface-driver), MATLAB Central File Exchange. Retrieved .