microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.3.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

katas/content/random_numbers/random_n_bits/solution.md

8lines · modepreview

Let's reuse the `RandomBit` operation from the "Generate A Single Random Bit" exercise again.
We'll generate $N$ random bits by calling `RandomBit` operation $N$ times, and treat the result as a binary notation of the integer we're looking for.
Since the maximum value of the number written with $N$ bits is $2^N - 1$, we don't need to do any extra checks to ensure that the result is within the given range.

@[solution]({
    "id": "random_numbers__random_n_bits_solution",
    "codePath": "Solution.qs"
})