1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2014 Intel Corporation 3 */ 4 5 #ifndef _RTE_RANDOM_H_ 6 #define _RTE_RANDOM_H_ 7 8 /** 9 * @file 10 * 11 * Pseudo-random Generators in RTE 12 */ 13 14 #include <stdint.h> 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 /** 21 * Seed the pseudo-random generator. 22 * 23 * The generator is automatically seeded by the EAL init with a timer 24 * value. It may need to be re-seeded by the user with a real random 25 * value. 26 * 27 * This function is not multi-thread safe in regards to other 28 * rte_srand() calls, nor is it in relation to concurrent rte_rand(), 29 * rte_rand_max() or rte_drand() calls. 30 * 31 * @param seedval 32 * The value of the seed. 33 */ 34 void 35 rte_srand(uint64_t seedval); 36 37 /** 38 * Get a pseudo-random value. 39 * 40 * The generator is not cryptographically secure. 41 * 42 * rte_rand(), rte_rand_max() and rte_drand() are multi-thread safe, 43 * with the exception that they may not be called by multiple 44 * _unregistered_ non-EAL threads in parallel. 45 * 46 * @return 47 * A pseudo-random value between 0 and (1<<64)-1. 48 */ 49 uint64_t 50 rte_rand(void); 51 52 /** 53 * Generates a pseudo-random number with an upper bound. 54 * 55 * This function returns an uniformly distributed (unbiased) random 56 * number less than a user-specified maximum value. 57 * 58 * rte_rand(), rte_rand_max() and rte_drand() are multi-thread safe, 59 * with the exception that they may not be called by multiple 60 * _unregistered_ non-EAL threads in parallel. 61 * 62 * @param upper_bound 63 * The upper bound of the generated number. 64 * @return 65 * A pseudo-random value between 0 and (upper_bound-1). 66 */ 67 uint64_t 68 rte_rand_max(uint64_t upper_bound); 69 70 /** 71 * Generates a pseudo-random floating point number. 72 * 73 * This function returns a non-negative double-precision floating random 74 * number uniformly distributed over the interval [0.0, 1.0). 75 * 76 * The generator is not cryptographically secure. 77 * 78 * rte_rand(), rte_rand_max() and rte_drand() are multi-thread safe, 79 * with the exception that they may not be called by multiple 80 * _unregistered_ non-EAL threads in parallel. 81 * 82 * @return 83 * A pseudo-random value between 0 and 1.0. 84 */ 85 double rte_drand(void); 86 87 #ifdef __cplusplus 88 } 89 #endif 90 91 92 #endif /* _RTE_RANDOM_H_ */ 93