how to get a random number with the sdk?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

how to get a random number with the sdk?

just a random number,the get opreat does not affact orther!

0 Likes
1 Solution

I just did a search on Google and there are a number of SW methods of generating a pseudo-random number that you can implement in the app. If you need a seed for your random number generator, you may use the Bluetooth clock as the first seed value:

/// This function returns the current native Bluetooth clock; this

/// counter is 28 bits, and ticks every 312.5 us and is adjusted for

/// drift through sleep, etc. To compute differences and times elapsed,

/// use bleapputils_diffNativeBtClks() or bleapputils_BtClksSince().

/// \return the counter value.

UINT32 bleapputils_currentNativeBtClk(void);

View solution in original post

4 Replies
asridharan
Employee
Employee
10 comments on KBA 5 comments on KBA First comment on KBA

With SDK 2.0, use:

/// Provides any number of random bit from the HW random bit generator.

/// \param buffer pointer to a buffer that can hold the random bits.

/// \param length Number of 32-bit numbers to generate.

extern void ulp_rand(UINT32* buffer, UINT32 length);

UINT32 rand_num;

ulp_rand(&rand_num, 1);

Unfortunately, this is not available with SDK 1.1.0.

0 Likes
Anonymous
Not applicable

Thanks for answer.

I use SDK 1.1.0.

For get a random number don`t use SDK ,do you have any good Suggestions?

0 Likes

I just did a search on Google and there are a number of SW methods of generating a pseudo-random number that you can implement in the app. If you need a seed for your random number generator, you may use the Bluetooth clock as the first seed value:

/// This function returns the current native Bluetooth clock; this

/// counter is 28 bits, and ticks every 312.5 us and is adjusted for

/// drift through sleep, etc. To compute differences and times elapsed,

/// use bleapputils_diffNativeBtClks() or bleapputils_BtClksSince().

/// \return the counter value.

UINT32 bleapputils_currentNativeBtClk(void);

My suggestion would be to find an implementation of the Mersenne Twister. It is widely available and implemented in a lot of languages (Mersenne twister - Wikipedia, the free encyclopedia). It is known to have an very long period.