ComScire QNG Model J20KP True Random Number Generator Users Manual From The Quantum World ComScire is a trademark of The Quantum World Corporation. Windows is a registered trademark of Microsoft Corporation. DOS is a trademark of International Business Machines, Corp. All other product names are trademarks of their producers. Copyright 1995-1998 by The Quantum World Corporation ComScire and The Quantum World Corporation make no representations, express or implied, with respect to this documentation and the software and QNG Device it describes, including without limitations, any implied warranties of merchantability or fitness for a particular purpose, all of which are expressly disclaimed. Users should be aware that included in the terms and conditions under which the QNG Device and its associated software is sold is a provision that ComScire and The Quantum World Corporation, and their distributors and dealers shall in no event be liable for any indirect, incidental or consequential damages, and that liability for direct damages shall be limited to the amount of the purchase price paid for the QNG Device. In addition to the foregoing, users should be aware that all software, documentation and hardware devices are subject to errors, omissions and defects. ComScire and The Quantum World Corporation do not recommend the use of the QNG Device and its associated software for applications in which errors, omissions or defects could threaten life, injury or significant loss. page 1 Table of Contents 1 Introduction................................ 2 2 Notes on Software Ver 1.0................... 3 3 Quick Start................................. 4 4 Hardware Installation....................... 5 5 Software Installation....................... 6 6 Data Modes.................................. 7 7 Mode Setting................................ 9 8 Error Returns............................... 10 9 Loading the Driver.......................... 11 10 Testing the QNG Device...................... 11 11 Bit Rate Selection.......................... 15 12 Specifications.............................. 15 13 DEMO Listings............................... 17 INTRODUCTION There are two basic types of random number generators: pseudo-random generators which use mathematical algorithms to produce apparently random sequences and true random generators which employ a physical signal source with inherently random statistics. The built-in random functions in all computer programming languages are the pseudo-random type and this source of "random" numbers has been convenient and adequate for many non-critical applications. Pseudo-Random generators have severe limitations in increasingly many applications as computing power expands and new techniques are developed in such areas as modeling using Monte Carlo and other methods, testing networks, communications and other systems, crytography and secure communications, parapsychological testing, numerical analysis, and sampling and decision making. Several applications have a fundamental requirement for a non-deterministic (inherently non-predictable) source of random numbers. Examples include secure communications where knowledge of the potential generating algorithm would greatly compromise the security of the encrypted message and parapsychological testing wherein any potential mind-device interaction would be precluded. The QNG Device is a high-quality, high-speed true random number generator designed to be very easy to install and use. Many tests, all of a statistical nature, may be used to quantify the quality of a sequence of random bits; however, there are two properties which are of primary importance. These are the serial dependence or auto-correlation and the probability of occurrence of 1's or 0's. Auto-correlation is the measure of the correlation (predictability) of the bits that follow the present bit and the desired or perfect value is 0 for all lag times following the present bit. page 2 The desired probability for both 1's and 0's is exactly .5 or equal numbers of each. As in most statistical tests neither of these properties can be measured exactly because their accuracy or confidence level increases as a function of the square root of the number of bits in the sample. The QNG Device contains an inherently random analog source whose output is converted to a sequence of binary bits. Blocks of four of these bits are sent through a circuit which produces output bits with greatly improved statistical properties at the expense of a four-to-one reduction in bit rate. The output bit statistics (1, 0 probabilities and auto-correlation function) are predictable by a proprietary algorithm given the statistics of the input bits which may be accurately measured in a relatively short period of time. This allows the specification of the QNG's statistical properties which are not directly measurable because of the extremely large sample size needed to detect the specified deviation from perfect randomness. Although no statistically significant defect in randomness has ever been detected in a QNG Device, a variety of sophisticated tests is being constantly applied with sample sizes up to tens of billions of bits. The standard software interface to the QNG Device is through a device driver similar to that used for disk access or printer control. This allows the user to obtain the various forms or built-in "modes" of random numbers as easily as reading and writing to the disk drive. These modes include, in various levels of precision; integers, uniform distributed fractions which is the type typically returned when using the RND or similar function in most programming languages, and normally distributed numbers. NOTES FOR SOFTWARE VERSION 1.0 No file, directory or subdirectory may be named "QNG" since this would cause the QNG Device to be opened instead of the intended file or directory. Booting up with a QNG Device connected to a parallel port will prohibit the use of that particular port for printing until the computer has been rebooted with no QNG Device attached to that port. The QNG Device will default to Polling instead of Interrupt for data acquisition when running Windows. This may result in a substantial reduction in random bit rate, particularly on slower computers. Running Windows is not recommended if maximum bit rates are desired. page 3 QUICK START 1. Turn off your computer and connect the QNG Device to any parallel port on your computer with the included cable. The parallel or "printer" port will have a female DB25 (25-pin) connector exposed on the outside of your computer and is usually the only one which will mate with the cable. 2. Turn on your computer and wait for it to boot up. 3. Insert the INSTALL diskette and type A:INSTALL or B:INSTALL for the appropriate drive and then press Enter. 4. Whenever a question is asked, press Enter. 5. Remove the INSTALL diskette before responding to the last question, "Reboot now?" Then press Enter and the computer will reboot and the driver will be installed in memory. 6. If desired you may now run the included verification/testing program: type CD\QNGDEV QNGTEST A brief "Phase one test" will be completed after which you will be prompted to "Continue"; press Enter. To exit the program press Escape. See Testing The QNG Device for a detailed explanation of these tests. 7. Demonstration programs in Basic, C and Fortran are included to illustrate the use of the QNG Device. The source files for these programs are: DEMO.BAS DEMO.C (These files are in the QNGDEV directory.) DEMO.FOR The Basic file may be run as is by starting Basic and loading \QNGDEV\DEMO.BAS and then running the program. The Fortran file must first be compiled by your Fortran compiler and then run. An executable (compiled) version of DEMO.C is included in the QNGDEV directory. To run this: type CD\QNGDEV DEMO page 4 HARDWARE INSTALLATION The QNG device may be plugged into any parallel printer port by means of a male-to-male DB-25 cable. No separate power connection is required; the device derives its power from the parallel port hardware. The driver software will auto-detect which parallel port is connected to the QNG device, or you may direct it to use a given port address and interrupt number. In order for the auto-detect logic to operate correctly, the QNG device must be connected to one of the 3 standard printer ports (3BC, 378, or 278). In addition, the device must be installed and operating at the time the computer is booted. If the driver does not find the device on any of the 3 standard ports, it will not load. If you manually select the port address, you may use any valid port address. The device need not be installed at the time the computer is booted. The system software will assign the parallel ports in order to the printers LPT1 through LPT3. To avoid possible conflicts with other software systems such as Windows, it is best to use a higher port number for the QNG device: 278 if possible, and then 378. The QNG device will operate with or without interrupts. Higher speed performance will be obtained if interrupts are used. If no interrupt is detected on bootup, or if you direct the driver to use interrupt 0, the driver will operate in polling (non-interrupt) mode. The standard printer interrupts are IRQ5 and IRQ7. Since most DOS software does not use printer interrupts, your parallel interface card has been factory set to either IRQ5 or IRQ7, or to no interrupt. The rules to follow when setting the QNG interrupt are: 1. The QNG device may not share an interrupt with a printer, while two or more printers may sometimes share an interrupt. 2. The auto-detect logic will only check interrupts IRQ5 and IRQ7, so one of these interrupts must be used in order for the auto-detect to work properly. 3. The QNG driver is able to use any interrupt between IRQ1 and IRQ7, if you have a custom interface card which supports it. A good choice other than IRQ5 or IRQ7 would be IRQ3 or IRQ4, usually used by the serial communication ports. page 5 SOFTWARE INSTALLATION A diskette is provided which contains the following software: READ.ME A text file containing the User Manual and up to date device information QNGDRV0.EXE 8086/286 version of device driver QNGDRV3.EXE 386/486/Pentium version QNGDRV0.COM COM version of device driver, for use with DOS versions below 5.0 QNGTEST.EXE Test and diagnostic utility INSTALL.EXE Installation utility DEMO.BAS Demonstration program in Basic DEMO.C Demonstration program in C, source code DEMO.EXE Executable version of DEMO.C DEMO.FOR Demonstration program in Fortran, source code To install the software, Insert the INSTALL diskette and type A:INSTALL or B:INSTALL for the appropriate drive and then press Enter. The installation program will copy all software to the current hard drive; normally this will be drive C. It will ask you what subdirectory to use; if you do not specify one, the default will be \QNGDEV. The specified subdirectory will be created if it does not already exist. The program will also copy the QNG device driver, QNGDRV, to the root directory of your hard drive. If you are running DOS 5.0 or later, it will install an .EXE version of the driver. Otherwise, it will install the .COM version. If your CPU is a 386 or higher, the program will install the QNGDRV3 version. This version is considerably faster because it uses 386 instructions. The installation program will show you a list of the parallel ports currently installed on your computer. If it is possible to identify which interrupt each port is using, the program will also give you this information. Finally, the installation program will add the following line to your CONFIG.SYS file on the root directory: DEVICE=QNGDRV0.EXE or DEVICE=QNGDRV3.EXE or DEVICE=QNGDRV0.COM This will cause the device driver to load each time the computer is booted up. page 6 If you choose, you may tell the installation program to skip the modification of the CONFIG.SYS file. In this case, you must add this line to the file yourself. You may also direct the driver to bypass its auto-detection logic and attach the device to a given port and interrupt number by including this information in the DEVICE command. The format is: DEVICE=QNGDRVx.EXE D=378 I=5 DEVICE=QNGDRVx.EXE D=378 I=0 (if no interrupt is used) If either the D or I parameter is specified, both D and I must be specified. D may be any valid port address between 0 and 3FC (hex); I may be any valid interrupt number between 1 and 7. After the installation is complete, you must re-boot the computer before the driver may be used. DATA MODES Software talks to the QNG device through a DOS device driver. The name of the device is "QNG", and it may be opened and read or written to the same as a standard device driver or file. The standard procedure would be: Open the device "QNG" for reading, in text mode. Read as many random numbers as you want (see formats below). Close the device. The QNG driver supports the following modes specifying the type of random numbers returned: MODE SETUP CODE FORMAT Uniform 16-bit 04 Returns uniformly distributed floating point numbers between 0 and 1: [0,1). Each number is represented by 6 digits; not all 6 digits are significant because the values are derived from 16-bit integers. Each value is preceded by a decimal point and followed by a carriage return and a newline character. Uniform 32-bit 08 Returns uniformly distributed numbers as in mode 04, but the values are derived from 32 bit integers. 10 digits are returned for each value. This is similar to the RND or like functions in many languages. page 7 Uniform 48-bit 0C Returns uniformly distributed numbers as in mode 04, but the values are derived from 48 bit integers. 14 digits are returned for each value. Normal, signed 88 Returns normally distributed numbers based on 32 bit integers. The range is arbitrarily limited to +/- 8 standard deviations; this limit would not be reached in normal use. Each value is followed by a carriage return and a newline character. High Precision 8C Returns normally distributed numbers as Normal, signed in mode 88, but the values are based on 40 bit integers and additional bits are used in the algorithm to produce optimum quality normal variates. Normal, unsigned 98 Returns normally distributed numbers between 0 and +8.0. High Precision 9C Returns normally distributed numbers as Normal, unsigned in mode 8C, but between 0 and +8. Basic hex 01 Returns a stream of ASCII hex digits, each representing a 4-bit random integer. In each 4-bit group, the most significant bit is the latest in time. No newline characters or decimal points are appended. Binary integer 10 Returns binary integers, 0 or 1. Short integer 11 Returns uniformly distributed integers from 0 to 15, inclusive. Integer 14 Returns uniformly distributed integers from 0 to 65,535, inclusive. In addition to the foregoing modes, a global enhanced mode may be set by adding 1000 to any setup code that is normally used. The enhanced mode reduces all defects in randomness measured by any statistical test to the point where no statistically significant pattern of any sort could ever be detected. The enhanced mode is intended for only the most critical applications as its activation reduces the random bit rate by one-half. page 8 Examples of the various mode values are: SETUP CODE MODE 10 Binary integer 1010 Binary integer, Enhanced 8010 Binary integer, Hard mode set (see Mode Setting section, Hard Modes) 9010 Binary integer, Enhanced, Hard mode set MODE SETTING The driver mode is set by writing a mode command to it. The mode command consists of the letter 'M', the setup code as shown above, and a newline. The mode change will not take effect until the newline character is received. The default mode is 08, uniform-32 bit; this will be used if no mode setting command is issued. There are several ways to send a mode command to the driver: 1. The driver may be opened for both reading and writing; the mode command may be sent as a text string to the device. Note that most I/O systems require that a SEEK or REWIND operation be done when changing mode between writing and reading. These commands have no effect on the QNG driver. 2. Close the device; open it for writing; write the command string; close it; and reopen it for reading. Note that this method is required in some languages, such as Basic, in which devices cannot be opened for simultaneous reading and writing. 3. In languages that support IOCTL commands, this is the easiest way because it does not affect the normal read channel. IOCTL command 3 is used to write to the device driver. A typical IOCTL command in C would be: ioctl(handle, 3, "M10\n", 4); HARD MODES A special precaution is needed in case 2, above. The driver normally resets its mode to 08 whenever it is opened. To keep this from overriding your mode setting, add 8000 to your mode setting. This gives you a "hard" mode setting which will not be reset when the device is opened. For example (in C): fputs("M8010\n", file); page 9 ERROR RETURNS ERROR 1 In case of an internal error (for example, the QNG device becoming disconnected or failing to operate during data reading) the driver software will return this text string instead of a numeric result. Your program should therefore include a test for alphabetic return data. ERROR 2 The QNG driver also runs a continuous test on all bit data to ensure that it maintains acceptable statistical characteristics. This test is applied to all incoming data, whether it is being used or not. Two tests are run on each block of 100,000 bits: 1. A 1/0 balance test: if the number of 1's exceeds plus or minus 3 standard deviations from the expected number for two blocks in a row, an error message will be returned. 2. An auto-correlation test: if the fourth order auto- correlation exceeds plus or minus 3 standard deviations from its expected value for two blocks in a row, an error message will be returned. This error message would be caused by stuck bits or other internal conditions which may not affect the overall data rate. OVERRUNS The driver reads data from the QNG device at a fixed rate of 10,000 or 20,000 bits per second (factory set for 20,000). Data are put into a buffer by the interrupt handler. If the user program requests data at a lower rate than this, the extra samples are discarded. No error message is given. If the user program requests data at a higher rate, the driver will cause the program to wait until the data becomes available. page 10 LOADING THE DRIVER The driver is loaded each time the computer is booted up. During the initialization phase, it does a number of tests to make sure that the device is functioning properly. These tests include: Auto-detect of the device code and interrupt being used. Measuring the data rate from the device. Testing that the auto-correlation of the bit stream is within limits. Testing whether the interrupt is on the rising or falling edge of the clock. The auto-detect logic may be overridden as described above, if you know which port you plan to use for the QNG device. When the driver recognizes that a printer port is connected to a QNG Device, it removes this printer port from the DOS list of installed printers. DOS will no longer recognize this port as a printer, and you will not be able to send print output to it. However, this process can be accident prone. To minimize the chance of difficulty, we recommend that you connect the QNG to a printer port which would normally be LPT3, thus leaving LPT1 and LPT2 unaffected. This means using the device code 278 (first choice) or 378. TESTING THE QNG DEVICE The software diskette includes a test program, QNGTEST.EXE, which runs a thorough test of the device. To run the test program, type: CD\QNGDEV QNGTEST The program has 2 phases. Phase 1 tests the basic operating configuration of the device, including: Data rate Which interrupts are in use, if any Whether the device is activating more than 1 interrupt Whether the interrupt occurs on the rising or falling edge of the clock (this affects the amount of time available to process an interrupt) The amount of time required to process the system clock tick (this can cause loss of data from the QNG device) page 11 The phase 2 tests include: One/zero balance of the data stream Auto-correlation of the data stream (first through eighth order) OQSO test (see reference 1) Entropy test (see reference 2) Graphic display of the number distribution (normally distributed numbers calculated from the random bits) Mean, standard deviation and kurtosis of the normally distributed numbers The phase 1 tests require about 5 seconds. The phase 2 tests may be continued as long as desired. A continuous display is provided of the test outputs. Phase 1 Display Phase 1 provides the following information: 1. If the driver is currently loaded, the port address and interrupt number which it is using. 2. The port addresses of all parallel port interfaces which are installed in the system. The phase 1 tests will be run on all of these interfaces at the same time, in order to detect any problems involving interactions between ports. 3. Using polling mode only (no interrupts enabled), the rate at which 4-bit nibbles are received from the device. This should be close to 2500 or 5000. 4. Using polling mode, the rate at which bits are received from the device. This will be four times the nibble rate. 5. A simple auto-correlation test measuring the auto- correlation between adjacent bits. The test is run for 1/4 second and a chi-squared value is computed. The probability, p, must be .01