The following demonstrates how to use Python language to download random data from an AlphaRNG device when used with AlphaRNG Entropy Server for Windows. The following code will only work when running AlphaRNG Entropy Server. Before using the following examples, make sure your Python project is targeted for Windows 64 bit platform and an AlphaRNG device is plugged into one of USB ports available. The AlphaRNG-64.dll is included in the software kit.

A sample source code for retrieving a random byte value from an AlphaRNG device when using Entropy Server for Windows and provided AlphaRNG-64.dll


import os
import sys
import ctypes

dll = ctypes.WinDLL("C:\\tools\\alrng-windows-binaries\\windows-x64-vs-2019\\AlphaRNG-64.dll")
func = dll.getEntropyAsByte
func.restype = ctypes.c_int

random = func()
if random > 255:
    raise Exception("Could not retreieve entropy byte. Is entropy server running?")
else:
    print ("Random byte: ", random)


A sample source code for retrieving an array of random bytes from an AlphaRNG device when using Entropy Server for Windows and provided AlphaRNG-64.dll


import os
import sys
import ctypes

byte_count = 10
byte_arr = ctypes.c_byte * byte_count
byte_arr_p = ctypes.POINTER(ctypes.c_byte)

dll = ctypes.WinDLL("C:\\tools\\alrng-windows-binaries\\windows-x64-vs-2019\\AlphaRNG-64.dll")
func = dll.getEntropy
func.restype = ctypes.c_int
func.argtypes = [byte_arr_p, ctypes.c_long]

entropy_bytes = byte_arr()

status = func(entropy_bytes, byte_count)
if status != 0:
    raise Exception("Could not retreieve entropy bytes. Is entropy server running?")

print("Retrieved random bytes:")
for x in entropy_bytes:
    print(x)