How to limit the Bcrypt library generated random numbers range?

Zsolt Kántor 80 Reputation points
2024-09-29T14:38:14.4133333+00:00

Hello!

I'm using the Bcrypt library BCryptGenRandom function to generate random numbers.

The BCryptGenRandom function generates UCHARs with range 0-255.

I need a range of 1-50. I know I can use the formula: rand_num % (MAX_NUM + 1 - MIN_NUM) + MIN_NUM. But this formula is not as precise as eventually setting a range and generating random numbers with that range directly from the Windows API.

Is there a way to configure and set a range using the Bcrypt interface?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,650 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.