pike.git / src / builtin.cmod

version» Context lines:

pike.git/src/builtin.cmod:2142:       /* Generates a number 0<=c<limit from random bits taken from the    int_buffer. Follows the NIST SP800-90A method for converting bit    sequences into bound numbers, described in section B.5.1.1, and    summarized as "throw away attempts that are too large". */    static INT_TYPE read_int(INT_TYPE limit)    {    if(limit <= 1) return 0;    int bits = my_log2(limit-1)+1;    UINT64 mask = (((UINT64)1)<<bits)-1; -  for(int i=0; i<1000; i++) +  int i; +  for(i=0; i<1000; i++)    {    if(THIS->buffer_bits < bits)    fill_int_buffer();    INT_TYPE ret = THIS->int_buffer&mask;    THIS->int_buffer >>= bits;    THIS->buffer_bits -= bits;    if( ret < limit )    return ret;    }    Pike_error("Failed to generate random data.\n");