Logo Search packages:      
Sourcecode: csound version File versions  Download package

PUBLIC int csoundRand31 ( int *  seedVal  ) 

Simple linear congruential random number generator: (*seedVal) = (*seedVal) * 742938285 % 2147483647 the initial value of *seedVal must be in the range 1 to 2147483646. Returns the next number from the pseudo-random sequence, in the range 1 to 2147483646.

Definition at line 47 of file random.c.

References csoundRand31().

Referenced by csoundRand31().

{
    uint64_t  tmp1;
    uint32_t  tmp2;

    /* x = (742938285 * x) % 0x7FFFFFFF */
    tmp1 = (uint64_t) ((int32_t) (*seedVal) * (int64_t) 742938285);
    tmp2 = (uint32_t) tmp1 & (uint32_t) 0x7FFFFFFF;
    tmp2 += (uint32_t) (tmp1 >> 31);
    tmp2 = (tmp2 & (uint32_t) 0x7FFFFFFF) + (tmp2 >> 31);
    (*seedVal) = (int) tmp2;
    return (int) tmp2;
}


Generated by  Doxygen 1.6.0   Back to index