microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
katas/content/random_numbers/random_n_bits/solution.md
8lines · modecode
| 1 | Let's reuse the `RandomBit` operation from the "Generate A Single Random Bit" exercise again. |
| 2 | 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. |
| 3 | 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. |
| 4 | |
| 5 | @[solution]({ |
| 6 | "id": "random_numbers__random_n_bits_solution", |
| 7 | "codePath": "Solution.qs" |
| 8 | }) |