1 /* 2 * Copyright 2018 Oticon A/S 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef BS_RAND_INLINE_H 8 #define BS_RAND_INLINE_H 9 10 #include <stdlib.h> 11 #include "bs_rand_main.h" 12 #include "bs_types.h" 13 14 #ifdef __cplusplus 15 extern "C" { 16 #endif 17 18 #define RAND_PROB_1 RAND_MAX 19 20 BSIM_INLINE uint bs_random_Bern(uint32_t probability); 21 22 /** 23 * Do a Bernouilli drop 24 * 25 * probability: number between 0 (0.0) and RAND_PROB_1 (1.0) 26 */ bs_random_Bern(uint32_t probability)27BSIM_INLINE uint bs_random_Bern(uint32_t probability){ 28 if ( (uint32_t)random() < probability ) 29 return 1; 30 else 31 return 0; 32 } 33 34 #ifdef __cplusplus 35 } 36 #endif 37 38 #endif 39