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

A sample source code for retrieving primitive type random values from SwiftRNG device when using Entropy Server for Windows

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;

namespace SwiftRngSampleApp2
{
    class Program
    {
	// Include the exact path to the SwiftRNG.dll (it uses additional dependencies from same location) available with the software kit.
        [DllImport("C:\\tools\\windows-x64\\x64\\Release\\SwiftRNG.dll", EntryPoint = "swftGetEntropyFromEntropyServer")]
        public static extern int getRandomDouble(ref double d, long byteCount);

        [DllImport("C:\\tools\\windows-x64\\x64\\Release\\SwiftRNG.dll", EntryPoint = "swftGetEntropyFromEntropyServer")]
        public static extern int getRandomInt(ref int i, long byteCount);

        [DllImport("C:\\tools\\windows-x64\\x64\\Release\\SwiftRNG.dll", EntryPoint = "swftGetEntropyFromEntropyServer")]
        public static extern int getRandomUInt64(ref UInt64 ui64, long byteCount);

        static void Main(string[] args)
        {
            double d = 0;
            int status = getRandomDouble(ref d, sizeof(double));
            if (status != 0)
            {
                Console.Out.WriteLine("Could not retrieve a random double, is Entropy Server running?");
            }
            else
            {
                Console.Out.WriteLine("Random double: " + d);
            }

            int n = 0;
            status = getRandomInt(ref n, sizeof(int));
            if (status != 0)
            {
                Console.Out.WriteLine("Could not retrieve a random int from SwiftRNG device");
            }
            else
            {
                Console.Out.WriteLine("Random int: " + n);
            }

            UInt64 ui64 = 0;
            status = getRandomUInt64(ref ui64, sizeof(UInt64));
            if (status != 0)
            {
                Console.Out.WriteLine("Could not retrieve a random Uint64 from SwiftRNG device");
            }
            else
            {
                Console.Out.WriteLine("Random Uint64: " + ui64);
            }

        }
    }
}