* This function generates and returns 64-bit pseudorandom number. * init_gen_rand or init_by_array must be called before this function. * The function gen_rand64 should not be called after gen_rand32, * unless an initialization is again executed. * @return 64-bit pseudorandom number */
| 480 | * @return 64-bit pseudorandom number |
| 481 | */ |
| 482 | uint64_t gen_rand64(sfmt_t *ctx) { |
| 483 | #if defined(BIG_ENDIAN64) && !defined(ONLY64) |
| 484 | uint32_t r1, r2; |
| 485 | uint32_t *psfmt32 = &ctx->sfmt[0].u[0]; |
| 486 | #else |
| 487 | uint64_t r; |
| 488 | uint64_t *psfmt64 = (uint64_t *)&ctx->sfmt[0].u[0]; |
| 489 | #endif |
| 490 | |
| 491 | assert(ctx->initialized); |
| 492 | assert(ctx->idx % 2 == 0); |
| 493 | |
| 494 | if (ctx->idx >= N32) { |
| 495 | gen_rand_all(ctx); |
| 496 | ctx->idx = 0; |
| 497 | } |
| 498 | #if defined(BIG_ENDIAN64) && !defined(ONLY64) |
| 499 | r1 = psfmt32[ctx->idx]; |
| 500 | r2 = psfmt32[ctx->idx + 1]; |
| 501 | ctx->idx += 2; |
| 502 | return ((uint64_t)r2 << 32) | r1; |
| 503 | #else |
| 504 | r = psfmt64[ctx->idx / 2]; |
| 505 | ctx->idx += 2; |
| 506 | return r; |
| 507 | #endif |
| 508 | } |
| 509 | |
| 510 | /* Generate a random integer in [0..limit). */ |
| 511 | uint64_t gen_rand64_range(sfmt_t *ctx, uint64_t limit) { |
no test coverage detected