1 /* prng.h -- Pseudo Random Numbers
3 * Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
5 * This file is part of the CoAP library libcoap. Please see
6 * README for terms of use.
11 * @brief Pseudo Random Numbers
20 * @defgroup prng Pseudo Random Numbers
28 * Fills \p buf with \p len random bytes. This is the default
29 * implementation for prng(). You might want to change prng() to use
30 * a better PRNG on your specific platform.
32 INLINE_API int coap_prng_impl(unsigned char *buf, size_t len)
35 *buf++ = rand() & 0xFF;
38 #else /* WITH_CONTIKI */
42 * Fills \p buf with \p len random bytes. This is the default
43 * implementation for prng(). You might want to change prng() to use
44 * a better PRNG on your specific platform.
47 contiki_prng_impl(unsigned char *buf, size_t len)
49 unsigned short v = random_rand();
50 while (len > sizeof(v))
52 memcpy(buf, &v, sizeof(v));
62 #define prng(Buf,Length) contiki_prng_impl((Buf), (Length))
63 #define prng_init(Value) random_init((unsigned short)(Value))
64 #endif /* WITH_CONTIKI */
68 * Fills \p Buf with \p Length bytes of random data.
72 #define prng(Buf,Length) coap_prng_impl((Buf), (Length))
77 * Called to set the PRNG seed. You may want to re-define this to
78 * allow for a better PRNG.
82 #define prng_init(Value) srand((unsigned long)(Value))
87 #endif /* _COAP_PRNG_H_ */