Download here.
HexPi (pronounced hex-pie) is a combination of three sub-projects.
There are two text files given under data
directory. The first one is called pi-hex.62500.txt
and contains first 62500 hexadecimal values of π. The second one is called pi-hex.1000000.txt
and contains first 1 million of the hex digits.
Why two files? These files are intended to be used by programs and if a program does not need beyond 62500 digits, there is no need to load a larger file.
This program code/pi-in-hex.c
contains minor improvements over the program piqpr8.c
by David H Bailey and uses the same BBP algorithm. The improvements include:
--start
or -s
. The argument indicates the position after which the hex digits are printed. For example, if -s 9
is passed, then the value of π will be printed from position 10. The default is 0.--nHexDigits
or -n
. The default is 10 (decimal). --verbose
or -v
. --help
or -h
.
A webservice has been created (using PHP backbone) that can be called as follows:
http://hexpi.sourceforge.net/webservices/index.php?s=0&n=20
With no s or n specified, the default value of s is randomized and n is set to 10.
It outputs an XML with the following format.
<Random-hex-pi> <start-position-in-decimal>0</start-position-in-decimal> <num-hex-digits>20</num-hex-digits> <value>243F6A8885A308D31319</value> </Random-hex-pi>Known limitation: The value of n should be multiple of 10.
Since π is an irrational number (meaning its digits never repeat itself), can successive sets of n such digits be grouped together and used as a series of random numbers? This is the primary motivation behind this project. Although I came up with this idea independently, upon further research, it turned out this idea is not unique. As a matter of fact, Blowfish, a cryptographic alorithm, uses few sets of values of π. Also, NIST lists various tests for validating the randomness of its digits.
Although the value of π can be used for any reason, the main objective of this webservice is to provide the hexadecimal digits that can be used as random numbers with subsequent calls. All that a user really need to do is to call it with s=s1, n=n1 one time and then call it again s=s1+n1 and n=n1 the next time.
This project is distributed as an open source repository under Lesser GNU Public License (LGPL).
You can download sources in tar+gzipped from here. Use 'tar -zxvf ...' command to ungzip and untar.
The code for pi-in-hex.c
is written (obviously) using ANSI-C. It is tested with gcc 4.4.7 20120313 (on Red Hat 4.4.7-3)
The webservice is written in PHP and is tested using PHP version PHP 5.3.3.
Once uncompressed, the downloaded source will create a directory named hexpi. It will also create the following subdirectories under this directory.
Bugs can be reported here.
Swapnajit Mitra is the author and maintainer of this project.