… | |
… | |
72 | #endif |
72 | #endif |
73 | |
73 | |
74 | // use C0X decltype for auto declarations until ISO C++ sanctifies them (if ever) |
74 | // use C0X decltype for auto declarations until ISO C++ sanctifies them (if ever) |
75 | #define auto(var,expr) decltype(expr) var = (expr) |
75 | #define auto(var,expr) decltype(expr) var = (expr) |
76 | |
76 | |
77 | // very ugly macro that basicaly declares and initialises a variable |
77 | // very ugly macro that basically declares and initialises a variable |
78 | // that is in scope for the next statement only |
78 | // that is in scope for the next statement only |
79 | // works only for stuff that can be assigned 0 and converts to false |
79 | // works only for stuff that can be assigned 0 and converts to false |
80 | // (note: works great for pointers) |
80 | // (note: works great for pointers) |
81 | // most ugly macro I ever wrote |
81 | // most ugly macro I ever wrote |
82 | #define statementvar(type, name, value) if (type name = 0) { } else if (((name) = (value)), 1) |
82 | #define statementvar(type, name, value) if (type name = 0) { } else if (((name) = (value)), 1) |
… | |
… | |
406 | uint32_t next (); |
406 | uint32_t next (); |
407 | |
407 | |
408 | // uniform distribution, 0 .. max (0, num - 1) |
408 | // uniform distribution, 0 .. max (0, num - 1) |
409 | uint32_t operator ()(uint32_t num) |
409 | uint32_t operator ()(uint32_t num) |
410 | { |
410 | { |
411 | return is_constant (num) |
411 | return !is_constant (num) ? get_range (num) // non-constant |
412 | ? (next () * (uint64_t)num) >> 32U |
412 | : num & (num - 1) ? (next () * (uint64_t)num) >> 32U // constant, non-power-of-two |
413 | : get_range (num); |
413 | : next () & (num - 1); // constant, power-of-two |
414 | } |
414 | } |
415 | |
415 | |
416 | // return a number within (min .. max) |
416 | // return a number within (min .. max) |
417 | int operator () (int r_min, int r_max) |
417 | int operator () (int r_min, int r_max) |
418 | { |
418 | { |