Unqualified, 1!:1 reads the entire file, but /dev/random is an endless stream.  
Can you try indexed read? As in

1!:11 '/dev/random';0 4 NB. Read 4 chars from file, starting at the beginning 

Note we're using one!:eleven, not one!:one .

Also, J includes its own PRNG, which you can use stand-alone, or to generate a 
seed for your PRNG.  See

http://www.jsoftware.com/help/dictionary/d640.htm
http://www.jsoftware.com/help/dictionary/d641.htm

-Dan

Please excuse typos; composed on a handheld device.

On Mar 13, 2013, at 4:48 AM, Jo van Schalkwyk <[email protected]> wrote:

> Hi All
> 
> I'd like to obtain a seed value (for a pseudorandom number generator) from
> /dev/random, but when I try:
> 
> RAND =: '/dev/random'
> read =: 1!:1
> seed =: read < RAND
> 
> ... I seem to get a null string. What am I doing wrong? (I'm using Ubuntu
> Linux v 12.10 and J701/2011-01-10/11:25).  In Perl (this works on my
> machine), I'd say:
> 
> #!/usr/bin/perl
> open(RAND, "/dev/random") or die "Can't open dev/random\n";
> read(RAND, $seed, 4);
> close(RAND);
> print("Value is ", unpack("H*", $seed), "\n");
> 
> I've tried running J from the command line under sudo just in case there
> was some 'security' issue, but this did nothing different. I'm not even
> sure if this is something to do with formatting, or inability to access
> /dev/random --- I suspect the former. When I say 3!:0 seed, I get type 2
> (literal).  If I use e.g. rf =: 1!:21 < '/dev/random' I obtain a file
> number, but I get the same null result on reading it, and an indexed read
> fails as expected.  I can't find anything on /dev/random on the J website.
> 
> Regards Jo.
> ----------------------------------------------------------------------
> 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