Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > what this program do

Reply
Thread Tools

what this program do

 
 
Morris Dovey
Guest
Posts: n/a
 
      03-27-2008
Richard Tobin wrote:

> See http://www.mathpropress.com/stan/bib...phy/spigot.pdf


Thanks for the link!

I got to thinking about how one might go about using the pi and e
digit strings to build a random number generator. Seemed like a
good idea at the time.

Then I wrote a tiny program to give me the digit frequencies and
decided that the idea might not be as good as I'd thought it
might be. With a initialized to 10000 and the printf() format
changed to "%.3ld" to produce the digits, I ran my little counter
program to get:

0 56
1 92
2 83
3 80
4 80
5 73
6 77
7 75
8 76
9 90

Which surprised me because I'd expected a much more even
distribution.

--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto/
 
Reply With Quote
 
 
 
 
Dik T. Winter
Guest
Posts: n/a
 
      03-27-2008
In article <fsg4bp$24pj$> (Richard Tobin) writes:
> In article <>,
> CBFalconer <> wrote:
> >I haven't the vaguest idea of the algorithm.

>
> See http://www.mathpropress.com/stan/bib...phy/spigot.pdf

....
> A similar algorithm for calculating the digits of e - also given in
> the same paper - is much easier to understand.


Right. When I wrote the program originally with a cow-orker the idea
was to see how the algorithm we knew for a long time for 'e' work out
for 'pi'. However, the algorithm for 'pi' is much shakier than that
for 'e'. In order to let it work correctly you should ensure that the
"digits" are always within certain bounds. For 'e' that is simple, it
is assured by the series development for 'e'. For 'pi' that is not the
case. And indeed, if you increase the arrays and the loop length etc.
you will find that at a certain point the program will start to give
wrong results. Once we had the program working I thought to decrease
its size and obfuscate the program as much as possible (although the
decrease in size was the most important for me). It had gone to a point
where even the C-beautifier of that time did not know what to do with it.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
 
Reply With Quote
 
 
 
 
Dik T. Winter
Guest
Posts: n/a
 
      03-27-2008
In article <> Morris Dovey <> writes:
....
> I got to thinking about how one might go about using the pi and e
> digit strings to build a random number generator. Seemed like a
> good idea at the time.
>
> Then I wrote a tiny program to give me the digit frequencies and
> decided that the idea might not be as good as I'd thought it
> might be. With a initialized to 10000 and the printf() format
> changed to "%.3ld" to produce the digits, I ran my little counter
> program to get:

....
> Which surprised me because I'd expected a much more even
> distribution.


You would have gotten that with the format string "%.4d". On the other
hand, using pi and e for random digits only works when they are normal
to base 10 (and there must be some additional randomness in the digits).
It is unknown whether they are.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
 
Reply With Quote
 
Morris Dovey
Guest
Posts: n/a
 
      03-27-2008
"Dik T. Winter" wrote:
>
> In article <> Morris Dovey <> writes:


> > Which surprised me because I'd expected a much more even
> > distribution.

>
> You would have gotten that with the format string "%.4d". On the other
> hand, using pi and e for random digits only works when they are normal
> to base 10 (and there must be some additional randomness in the digits).
> It is unknown whether they are.


I tried that, with this result:

0 74
1 92
2 83
3 80
4 80
5 73
6 77
7 75
8 76
9 90

which is more uniform, but less so than I'd expected.

The "digit spigot" is very interesting!

Thanks

--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto/
 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      03-27-2008
In article <>,
Morris Dovey <> wrote:
>which is more uniform, but less so than I'd expected.


See http://mathworld.wolfram.com/PiDigits.html, which includes a table
of the distribution of digits in the first 10^n places for n up to 12,
and says it "shows no statistically significant departure from a
uniform distribution".

-- Richard
--
:wq
 
Reply With Quote
 
Richard Bos
Guest
Posts: n/a
 
      03-27-2008
(Richard Tobin) wrote:

> In article <>,
> CBFalconer <> wrote:
> >I haven't the vaguest idea of the algorithm.

>
> See http://www.mathpropress.com/stan/bib...phy/spigot.pdf
>
> In short: if you represent pi in the "mixed-radix" base where the
> values for each digit overflow at
>
> . 1/3 2/5 3/7 4/9 ...
>
> (that is, the first digit after the point represents thirds, the
> second multiples of 1/3 * 2/5, and so on),
>
> then the representation of pi is
>
> 2 . 2 2 2 2 ...
>
> and the program works by converting that to base 10 (actually, 10000).


Very clever.

Richard
 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      03-27-2008
Morris Dovey <> writes:

> Richard Tobin wrote:
>
>> See http://www.mathpropress.com/stan/bib...phy/spigot.pdf

>
> Thanks for the link!
>
> I got to thinking about how one might go about using the pi and e
> digit strings to build a random number generator. Seemed like a
> good idea at the time.
>
> Then I wrote a tiny program to give me the digit frequencies and
> decided that the idea might not be as good as I'd thought it
> might be. With a initialized to 10000 and the printf() format
> changed to "%.3ld" to produce the digits, I ran my little counter
> program to get:
>
> 0 56
> 1 92
> 2 83
> 3 80
> 4 80
> 5 73
> 6 77
> 7 75
> 8 76
> 9 90
>
> Which surprised me because I'd expected a much more even
> distribution.


Looks even enough to me considering the numbers involved.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to javac a java program w/ another java program which is w/o a main method cjeffwang@yahoo.com Java 1 10-31-2005 04:25 AM
System program/ Application program ?? Parvsandhu Java 2 07-11-2005 09:08 AM
how to convert a java program to an exe program ola Java 3 02-16-2004 09:42 AM
Calling Java program in another Java program Rey Java 4 12-12-2003 10:18 PM
passing data between Java program and C program--help pipi Java 1 07-21-2003 05:02 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57