microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
katas/content/key_distribution/random_array/solution.md
10lines · modecode
| 1 | You need to do three steps to generate an array of random values: |
| 2 | |
| 3 | 1. Create a mutable array of size $N$ - it will need a default value that can be `false`. |
| 4 | 2. For each index from $0$ to $N-1$, choose one of the two values `true` or `false` at random, and assign that value to the array element at that index. You could choose a random bit by allocating a qubit, preparing it in the $\ket{+}$ state, and measuring it. However, you don't need those bits to have quantum origin, so you can use a Q# library operation `DrawRandomInt` instead. |
| 5 | 3. Finally, return the generated array. |
| 6 | |
| 7 | @[solution]({ |
| 8 | "id": "key_distribution__random_array_solution", |
| 9 | "codePath": "./Solution.qs" |
| 10 | }) |
| 11 | |