Here is a cool function based on obtaining the yth digit of ln 2 
http://en.wikipedia.org/wiki/Spigot_algorithm

iofLn =: (([: +/ [:  % ((>: i.11) ^~ [) * (>: i.11) + ]) +  1|[: +/ (>:@:i.@]) 
%~ (>:@:i.@]) |  [ ^ ] - (>:@:i.@]))


  #: 2x (256&([ | <.@*))@:iofLn 77 
1 1 0 1 0 1 0

You can check here that it will return 8 bits from the expansion of log 2 
starting at y (a 7 bit output above means leading 0)

http://oeis.org/A068426/list

but some cool properties is that the function works for any x, and is pretty 
fast even with large x

  412123123123123112313123323x (256&( <.@*))@:iofLn 81 
179

it gets progressively slower with larger y.  This is mostly due to it doing 
exponentiations for i.y

Although the byte generated by a large x at an arbitrary expansion bit has no 
relationship to a named constant that I know of, the 2 features just discussed 
makes this a good random number generator in circumstances that you want it to 
be purposefully slow (cryptography where slow generators don't bother someone 
with the right password, but prevent brute force attacks by slowing them down)

another feature is that although the precision is tuned to get the correct 8 
bits from ln 2, you can get larger numbers out of it depending on y.  The 
precision doesn't matter if you just want random numbers.

  23x iofLn 41 
85146025807389710516223130965220073r128382601906744088551296320725653600

  23x (4294967296&([ | <.@*))@:iofLn 41 
2848512109

(The precision comes from i.11 constant where 11 is 3 bits higher than the 8 
bits precision taken)


----- Original Message -----
From: EelVex <[email protected]>
To: Programming forum <[email protected]>
Cc: 
Sent: Tuesday, January 6, 2015 5:32 PM
Subject: Re: [Jprogramming] nth digit of pi

Maybe this will help a bit:

http://codegolf.stackexchange.com/questions/1519/calculate-digits-of-pi


On Tue, Jan 6, 2015 at 10:50 PM, 'Pascal Jasmin' via Programming <
[email protected]> wrote:

> I don't really understand this well:
>
>
> http://en.wikipedia.org/wiki/Approximations_of_%CF%80#Digit_extraction_methods
>
> is there a J program for finding the y th digit of pi (any base is ok)
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to