]> git.ozlabs.org Git - ccan/blob - ccan/charset/test/common.h
container_of: don't put member_ptr in container_off.
[ccan] / ccan / charset / test / common.h
1 #include <stdint.h>
2 #include <stdlib.h>
3
4 /*
5  * Finds a pseudorandom 32-bit number from 0 to 2^32-1 .
6  * Uses the BCPL linear congruential generator method.
7  *
8  * Used instead of system RNG to ensure tests are consistent.
9  */
10 static uint32_t rand32(void)
11 {
12 #if 0
13         /*
14          * Tests should be run with a different random function
15          * from time to time.  I've found that the method below
16          * sometimes behaves poorly for testing purposes.
17          * For example, rand32() % N might only return even numbers.
18          */
19         assert(RAND_MAX == 2147483647);
20         return ((random() & 0xFFFF) << 16) | (random() & 0xFFFF);
21 #else
22         static uint32_t rand32_state = 0;
23         rand32_state *= (uint32_t)0x7FF8A3ED;
24         rand32_state += (uint32_t)0x2AA01D31;
25         return rand32_state;
26 #endif
27 }