Re: Extremely poor performance crunching random numbers under PIV-FC5

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux