NordicPlayground / nRF51-ble-bcast-mesh

Other
324 stars 121 forks source link

How to get the seed for rand.h in rbc mesh #106

Closed rifatmahmud closed 8 years ago

rifatmahmud commented 8 years ago

How to randomly change the seed in this function while generating random number? uint32_t rand_prng_seed(prng_t* p_prng);

daviddedwin commented 8 years ago

If you want a random number you can get it from the softdevice call to the RNG hardware. See https://devzone.nordicsemi.com/question/7244/random-pool-numbers-documentation/ for a bit more detail. Will that work for you ?

rifatmahmud commented 8 years ago

Ok, but just wondering, what rand library in rbc mesh is for? Can I use that, getting the seed from timer or rtc?

trond-snekvik commented 8 years ago

You can seed the prng with rand_prng_seed(), which seeds from the SD-pool (hardware rng). The prng is based on Bob Jenkins' small PRNG, which has decent cycles and uniformness, but it's not suited for cryptographic purposes. You can also use the rand_hw_rng_get() for accessing the sd_rand, but you could also use the SD interface directly.