The RAVA Python Driver provides a Python interface for communicating with RAVA8 True Random Number Generator (TRNG) devices running the RAVA8 Firmware.
- USB communication with RAVA8 devices
- Random bit, byte, integer and floating-point generation
- TCP relay server supporting simultaneous access by multiple TCP clients
- Python 3.11 or later
- pyserial
The driver is available on PyPI as rng_rava. After creating and activating a Python virtual environment, install it with:
pip install rng_rava
import rng_rava as rava
# Find the serial number of the attached RAVA devices
rava_sns = rava.find_rava_sns()
# Create a RNG_USB instance and connect to the first device
rng = rava.RAVA_USB()
rng.open(rava_sns[0])
# Measure 100 pulse counts
pc_a, pc_b = rng.gen_pulse_counts(n_counts=100)
# Generate a random bit XORing both cores
bit = rng.gen_bit(rng_cores=rava.R_RngCores.AB_XOR)
# Generate 100 random bytes from each entropy core
bytes_a, bytes_b = rng.gen_bytes(n_bytes=100)
# Generate 100 8-bit integers between 0 and 99
ints8 = rng.gen_int8s(n_ints=100, delta=100)
# Generate 100 16-bit integers between 0 and 999
ints16 = rng.gen_int16s(n_ints=100, delta=1000)
# Generate 100 32-bit floats ranging between 0 and 1
floats = rng.gen_floats(n_floats=100)
# Close RAVA device
rng.close()
Additional examples are available in the examples/ directory.
The driver also supports communication over TCP through a relay server, allowing one or more remote clients to access a locally connected RAVA8 device.
Start the TCP server with:
python3 -m rng_rava.tcp_srv --host 127.0.0.1 --port 4884
The following example connects to the TCP server and uses the same API as the USB driver:
import rng_rava as rava
# Connect to the RAVA TCP server
rng = rava.RAVA8_TCP()
rng.open('127.0.0.1', 4884)
# Generate 100 random bytes from each entropy core
bytes_a, bytes_b = rng.gen_bytes(n_bytes=100)
...
# Close the connection
rng.close()
| Firmware Version | Driver Version |
|---|---|
| v1.0.0 | v1.1.0 – v1.2.1 |
| ≥ v2.0.0 | ≥ v2.0.0 |
| ≥ v3.0.0 | ≥ v3.0.0 |
