You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2020/11/12 19:17:01 UTC

[GitHub] [mynewt-nimble] andrzej-kaczmarek commented on a change in pull request #880: nimble/ll: Use true RNG instead of rand

andrzej-kaczmarek commented on a change in pull request #880:
URL: https://github.com/apache/mynewt-nimble/pull/880#discussion_r522354540



##########
File path: nimble/controller/src/ble_ll_rand.c
##########
@@ -120,6 +120,18 @@ ble_ll_rand_data_get(uint8_t *buf, uint8_t len)
     return BLE_ERR_SUCCESS;
 }
 
+/* Simple wrapper to allow easy replacement of rand() */
+int
+ble_ll_rand(void)
+{
+    int data;
+
+    ble_ll_rand_data_get((uint8_t *)&data, sizeof(data));
+
+    /* rand returns signed integer but in range 0-RAND_MAX */
+    return data & RAND_MAX;

Review comment:
       I would just use `uint32_t` as return type and return data directly - this does not need to compatible with `rand()` since our code does not really care, it will limit returned value anyway if needed.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org