11 probdist_init(struct probdist
*pd
, int bsize2
)
13 if (!pd
) pd
= malloc(sizeof(*pd
));
15 pd
->moves
= calloc(bsize2
, sizeof(pd
->moves
[0]));
21 probdist_pick(struct probdist
*pd
)
23 assert(pd
->total
> -1); // -1..0 is rounding error
24 if (pd
->total
< __FLT_EPSILON__
)
26 float stab
= (float) fast_random(65536) / 65536 * pd
->total
;
28 //fprintf(stderr, "stab %f / %f\n", stab, pd->total);
29 for (coord_t c
= 0; c
< pd
->bsize2
; c
++) {
34 //fprintf(stderr, "overstab %f (total %f, sum %f)\n", stab, pd->total, sum);
35 // This can sometimes happen when also punching due to rounding errors,.
36 // Just assert that the difference is tiny.
37 assert(fabs(pd
->total
- stab
) < 1);
42 probdist_done(struct probdist
*pd
) {