The following demonstrates how to use AlphaRNG Software API in C++ language to download random data from a AlphaRNG device when used with Entropy Server for Windows. The following code will only work when running AlphaRNG Entropy Server. This is the recommended way for achieving maximum concurrent speed and performance. Before using the following example, make sure the AlphaRNG device is plugged into one of USB ports available and entropy-server.exe is running on same system.

A C++ sample source code for retrieving random values from AlphaRNG device when using Entropy Server for Windows through a named pipe connection.

#include <EntropyServerConnector.h>
#include <iostream>

using namespace alpharng;

/**
 * @return 0 if ran successfully
 */
int main() {

	const int count = 10;
	unsigned char rnd_byte_buffer[count];
	EntropyServerConnector pipe;

	cout << "------------------------------------------------------------------------------" << endl;
	cout << "--- Sample C++ program for retrieving random bytes from the entropy server ---" << endl;
	cout << "------------------------------------------------------------------------------" << endl;

	// Connecting to the entropy server
	if (!pipe.open_named_pipe()) {
		cerr << pipe.get_last_error() << endl;
		cerr << "Is entropy server running?" << endl;
		return -1;
	}

	cout << endl << "Pipe open successfully" << endl << endl;

	cout << "*** Generating " << count << " random bytes ***" << endl;

	// Retrieve random bytes from device
	if (!pipe.get_entropy(rnd_byte_buffer, sizeof(rnd_byte_buffer))) {
		cerr << pipe.get_last_error() << endl;
		return -1;
	}

	for (int i = 0; i < count; i++) {
		cout << "random byte " << i << "-> " << (int)rnd_byte_buffer[i] << endl;
	}

	return 0;
}