* This function initializes the internal state array with a 32-bit * integer seed. * * @param seed a 32-bit integer used as the seed. */
| 605 | * @param seed a 32-bit integer used as the seed. |
| 606 | */ |
| 607 | sfmt_t *init_gen_rand(uint32_t seed) { |
| 608 | void *p; |
| 609 | sfmt_t *ctx; |
| 610 | int i; |
| 611 | uint32_t *psfmt32; |
| 612 | |
| 613 | if (posix_memalign(&p, sizeof(w128_t), sizeof(sfmt_t)) != 0) { |
| 614 | return NULL; |
| 615 | } |
| 616 | ctx = (sfmt_t *)p; |
| 617 | psfmt32 = &ctx->sfmt[0].u[0]; |
| 618 | |
| 619 | psfmt32[idxof(0)] = seed; |
| 620 | for (i = 1; i < N32; i++) { |
| 621 | psfmt32[idxof(i)] = 1812433253UL * (psfmt32[idxof(i - 1)] |
| 622 | ^ (psfmt32[idxof(i - 1)] >> 30)) |
| 623 | + i; |
| 624 | } |
| 625 | ctx->idx = N32; |
| 626 | period_certification(ctx); |
| 627 | ctx->initialized = 1; |
| 628 | |
| 629 | return ctx; |
| 630 | } |
| 631 | |
| 632 | /** |
| 633 | * This function initializes the internal state array, |
no test coverage detected