mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-01-25 02:07:54 +00:00
[Core] Add new switch_rand() a compliant random number generator API. Add a unit-test.
* [Core] Add new switch_rand() a compliant random number generator API. Add a unit-test. * Fall back to rand() on unsupported platforms compile time.
This commit is contained in:
@@ -53,6 +53,27 @@ FST_CORE_BEGIN("./conf")
|
||||
}
|
||||
FST_TEARDOWN_END()
|
||||
|
||||
FST_TEST_BEGIN(test_switch_rand)
|
||||
{
|
||||
int i, c = 0;
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "\nLet's generate a few random numbers.\n");
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
uint32_t rnd = switch_rand();
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Random number %d\n", rnd);
|
||||
|
||||
if (rnd == 1) {
|
||||
c++;
|
||||
}
|
||||
}
|
||||
|
||||
/* We do not expect all random numbers to be 1 all 10 times. That would mean we have an error OR we are lucky to have 10 random ones! */
|
||||
fst_check(c < 10);
|
||||
}
|
||||
FST_TEST_END()
|
||||
|
||||
FST_TEST_BEGIN(test_switch_uint31_t_overflow)
|
||||
{
|
||||
switch_uint31_t x;
|
||||
|
||||
Reference in New Issue
Block a user