Extremely poor performance crunching random numbers under PIV-FC5

Andy Green andy at warmcat.com
Fri May 19 06:55:12 UTC 2006


BankHacker wrote:

> Please, could you tell me how to use the structure correctly? Thanks.
> 
> Any hint to continue will be appreciate.

Looks like initstate_r() is a big secret and the whole deal is poorly 
documented.

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=6273

Here is my guess at the meaning of it all that appears to work:

     #include <stdio.h>
     #include <stdlib.h>
     #include <fcntl.h>

     int nRandom;
     struct random_data randomdataState;
     char szBufferState[1024];


     int main(int argc, char ** argv) {
         int n;

         int fd=open("/dev/urandom", O_RDONLY);
         if(fd<1) { perror("unable to open /dev/urandom"); return 1; }

         read(fd, szBufferState, sizeof(szBufferState));
         close(fd);

         initstate_r(*((int *)szBufferState), 
(szBufferState+sizeof(int)), sizeof(szBufferState)-sizeof(int), 
&randomdataState);

         for(n=0;n<2048;n++) {
                 random_r(&randomdataState, &nRandom);
                 printf("%d\n", nRandom);
         }

         return (0);
     }

-Andy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 4492 bytes
Desc: S/MIME Cryptographic Signature
Url : http://lists.fedoraproject.org/pipermail/users/attachments/20060519/c58a05f3/attachment-0002.bin 


More information about the users mailing list