Skip to content

Commit ec4e63b

Browse files
committed
review-2
1 parent 3c4f7f0 commit ec4e63b

File tree

9 files changed

+143
-142
lines changed

9 files changed

+143
-142
lines changed
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
### YamlMime:ModuleUnit
2-
uid: learn.quantum.qsharp-create-first-quantum-development-kit.1-introduction
3-
title: Introduction
4-
metadata:
5-
title: Introduction
6-
description: Introduction
7-
ms.date: 10/30/2024
8-
author: azure-quantum-content
9-
ms.author: quantumdocwriters
10-
11-
ms.topic: unit
12-
durationInMinutes: 1
13-
content: |
14-
[!include[](includes/1-introduction.md)]
1+
### YamlMime:ModuleUnit
2+
uid: learn.quantum.qsharp-create-first-quantum-development-kit.1-introduction
3+
title: Introduction
4+
metadata:
5+
title: Introduction
6+
description: Introduction
7+
ms.date: 06/05/2025
8+
author: azure-quantum-content
9+
ms.author: quantumdocwriters
10+
11+
ms.topic: unit
12+
durationInMinutes: 1
13+
content: |
14+
[!include[](includes/1-introduction.md)]
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
### YamlMime:ModuleUnit
2-
uid: learn.quantum.qsharp-create-first-quantum-development-kit.qsharp-structure
3-
title: What are the main components of a Q# program?
4-
metadata:
5-
title: How are Q# programs structured?
6-
description: Learn the structure of a basic Q# program.
7-
ms.date: 10/30/2024
8-
author: azure-quantum-content
9-
ms.author: quantumdocwriters
10-
11-
ms.topic: unit
12-
durationInMinutes: 6
13-
content: |
14-
[!include[](includes/2-qsharp-structure.md)]
15-
1+
### YamlMime:ModuleUnit
2+
uid: learn.quantum.qsharp-create-first-quantum-development-kit.qsharp-structure
3+
title: What are the main components of a Q# program?
4+
metadata:
5+
title: How are Q# programs structured?
6+
description: Learn the structure of a basic Q# program.
7+
ms.date: 06/05/2025
8+
author: azure-quantum-content
9+
ms.author: quantumdocwriters
10+
11+
ms.topic: unit
12+
durationInMinutes: 6
13+
content: |
14+
[!include[](includes/2-qsharp-structure.md)]
15+
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
### YamlMime:ModuleUnit
2-
uid: learn.quantum.qsharp-create-first-quantum-development-kit.4-random-bit-generator
3-
title: Exercise Part 1 - Create a quantum random bit generator
4-
metadata:
5-
title: Exercise - Create a quantum random bit generator
6-
description: Write Q# code that generates a single random bit.
7-
ms.date: 10/30/2024
8-
author: azure-quantum-content
9-
ms.author: quantumdocwriters
10-
11-
ms.topic: unit
12-
show_latex: true
13-
durationInMinutes: 8
14-
content: |
15-
[!include[](includes/3-random-bit-generator.md)]
1+
### YamlMime:ModuleUnit
2+
uid: learn.quantum.qsharp-create-first-quantum-development-kit.4-random-bit-generator
3+
title: Exercise Part 1 - Create a quantum random bit generator
4+
metadata:
5+
title: Exercise - Create a quantum random bit generator
6+
description: Write Q# code that generates a single random bit.
7+
ms.date: 06/05/2025
8+
author: azure-quantum-content
9+
ms.author: quantumdocwriters
10+
11+
ms.topic: unit
12+
show_latex: true
13+
durationInMinutes: 8
14+
content: |
15+
[!include[](includes/3-random-bit-generator.md)]
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
### YamlMime:ModuleUnit
2-
uid: learn.quantum.qsharp-create-first-quantum-development-kit.5-random-number-generator
3-
title: Exercise Part 2 - Create a quantum random number generator
4-
metadata:
5-
title: Exercise - Create a quantum random number generator
6-
description: Write classical code to extend your random bit program to generate larger numbers.
7-
ms.date: 10/30/2024
8-
author: azure-quantum-content
9-
ms.author: quantumdocwriters
10-
11-
ms.topic: unit
12-
show_latex: true
13-
durationInMinutes: 10
14-
content: |
15-
[!include[](includes/4-random-number-generator.md)]
1+
### YamlMime:ModuleUnit
2+
uid: learn.quantum.qsharp-create-first-quantum-development-kit.5-random-number-generator
3+
title: Exercise Part 2 - Create a quantum random number generator
4+
metadata:
5+
title: Exercise - Create a quantum random number generator
6+
description: Write classical code to extend your random bit program to generate larger numbers.
7+
ms.date: 06/05/2025
8+
author: azure-quantum-content
9+
ms.author: quantumdocwriters
10+
11+
ms.topic: unit
12+
show_latex: true
13+
durationInMinutes: 10
14+
content: |
15+
[!include[](includes/4-random-number-generator.md)]

learn-pr/quantum/qsharp-create-first-quantum-development-kit/5-knowledge-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ metadata:
77
author: azure-quantum-content
88
ms.author: quantumdocwriters
99

10-
ms.date: 10/30/2024
10+
ms.date: 06/05/2025
1111
ms.topic: unit
1212
ai-usage: ai-assisted
1313
durationInMinutes: 7
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
### YamlMime:ModuleUnit
2-
uid: learn.quantum.qsharp-create-first-quantum-development-kit.8-summary
3-
title: Summary
4-
metadata:
5-
title: Summary
6-
description: Summary
7-
ms.date: 10/30/2024
8-
author: azure-quantum-content
9-
ms.author: quantumdocwriters
10-
11-
ms.topic: unit
12-
durationInMinutes: 1
13-
content: |
14-
[!include[](includes/6-summary.md)]
15-
1+
### YamlMime:ModuleUnit
2+
uid: learn.quantum.qsharp-create-first-quantum-development-kit.8-summary
3+
title: Summary
4+
metadata:
5+
title: Summary
6+
description: Summary
7+
ms.date: 06/05/2025
8+
author: azure-quantum-content
9+
ms.author: quantumdocwriters
10+
11+
ms.topic: unit
12+
durationInMinutes: 1
13+
content: |
14+
[!include[](includes/6-summary.md)]
15+

learn-pr/quantum/qsharp-create-first-quantum-development-kit/includes/4-random-number-generator.md

Lines changed: 66 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,22 @@ For the complete random number generator, you're going to reuse the operation de
5858
The `GenerateRandomBit` operation should look like this:
5959

6060
```qsharp
61-
operation GenerateRandomBit() : Result {
62-
// Allocate a qubit.
63-
use q = Qubit();
61+
operation GenerateRandomBit() : Result {
62+
// Allocate a qubit.
63+
use q = Qubit();
6464
65-
// Set the qubit into superposition of 0 and 1 using the Hadamard
66-
H(q);
65+
// Set the qubit into superposition of 0 and 1 using the Hadamard
66+
H(q);
6767
68-
// Measure the qubit and store the result.
69-
let result = M(q);
68+
// Measure the qubit and store the result.
69+
let result = M(q);
7070
71-
// Reset qubit to the |0〉 state.
72-
Reset(q);
71+
// Reset qubit to the |0〉 state.
72+
Reset(q);
7373
74-
// Return the result of the measurement.
75-
return result;
76-
}
74+
// Return the result of the measurement.
75+
return result;
76+
}
7777
```
7878

7979
### Define the quantum random number operation
@@ -83,30 +83,30 @@ Here, you define the `GenerateRandomNumberInRange` operation. This operation rep
8383
Copy the following code and paste it before the `GenerateRandomBit` operation into your `Main.qs` file:
8484

8585
```qsharp
86-
/// Generates a random number between 0 and `max`.
87-
operation GenerateRandomNumberInRange(max : Int) : Int {
88-
// Determine the number of bits needed to represent `max` and store it
89-
// in the `nBits` variable. Then generate `nBits` random bits which will
90-
// represent the generated random number.
91-
mutable bits = [];
92-
let nBits = BitSizeI(max);
93-
for idxBit in 1..nBits {
94-
set bits += [GenerateRandomBit()];
95-
}
96-
let sample = ResultArrayAsInt(bits);
97-
98-
// Return random number if it is within the requested range.
99-
// Generate it again if it is outside the range.
100-
return sample > max ? GenerateRandomNumberInRange(max) | sample;
86+
/// Generates a random number between 0 and `max`.
87+
operation GenerateRandomNumberInRange(max : Int) : Int {
88+
// Determine the number of bits needed to represent `max` and store it
89+
// in the `nBits` variable. Then generate `nBits` random bits which will
90+
// represent the generated random number.
91+
mutable bits = [];
92+
let nBits = BitSizeI(max);
93+
for idxBit in 1..nBits {
94+
set bits += [GenerateRandomBit()];
10195
}
96+
let sample = ResultArrayAsInt(bits);
97+
98+
// Return random number if it is within the requested range.
99+
// Generate it again if it is outside the range.
100+
return sample > max ? GenerateRandomNumberInRange(max) | sample;
101+
}
102102
```
103103

104104
Let's take a moment to review the new code.
105105

106-
* You need to calculate the number of bits needed to express integers up to `max`. The `BitSizeI` function from the `Microsoft.Quantum.Math` library converts an integer to the number of bits needed to represent it.
107-
* The `GenerateRandomNumberInRange` operation uses a `for` loop to generate random numbers until it generates one that's equal to or less than `max`. The `for` loop works exactly the same as a `for` loop in other programming languages.
108-
* The variable `bits` is a mutable variable. A mutable variable is one that can change during the computation. You use the `set` directive to change a mutable variable's value.
109-
* The `ResultArrayAsInt` function comes from the `Microsoft.Quantum.Convert` library. This function converts the bit string to a positive integer.
106+
- You need to calculate the number of bits needed to express integers up to `max`. The `BitSizeI` function from the `Microsoft.Quantum.Math` library converts an integer to the number of bits needed to represent it.
107+
- The `GenerateRandomNumberInRange` operation uses a `for` loop to generate random numbers until it generates one that's equal to or less than `max`. The `for` loop works exactly the same as a `for` loop in other programming languages.
108+
- The variable `bits` is a mutable variable. A mutable variable is one that can change during the computation. You use the `set` directive to change a mutable variable's value.
109+
- The `ResultArrayAsInt` function comes from the `Microsoft.Quantum.Convert` library. This function converts the bit string to a positive integer.
110110

111111
### Add an entry point
112112

@@ -118,6 +118,7 @@ Copy and paste the following code to your `Main.qs` file:
118118
operation Main() : Int {
119119
let max = 100;
120120
Message($"Sampling a random number between 0 and {max}: ");
121+
121122
// Generate random number in the 0..max range.
122123
return GenerateRandomNumberInRange(max);
123124
}
@@ -131,48 +132,48 @@ Your `Main.qs` file should look like this:
131132
import Microsoft.Quantum.Convert.*;
132133
import Microsoft.Quantum.Math.*;
133134
134-
operation Main() : Int {
135-
let max = 100;
136-
Message($"Sampling a random number between 0 and {max}: ");
137-
138-
// Generate random number in the 0..max range.
139-
return GenerateRandomNumberInRange(max);
140-
}
135+
operation Main() : Int {
136+
let max = 100;
137+
Message($"Sampling a random number between 0 and {max}: ");
141138
142-
/// Generates a random number between 0 and `max`.
143-
operation GenerateRandomNumberInRange(max : Int) : Int {
144-
// Determine the number of bits needed to represent `max` and store it
145-
// in the `nBits` variable. Then generate `nBits` random bits which will
146-
// represent the generated random number.
147-
mutable bits = [];
148-
let nBits = BitSizeI(max);
149-
for idxBit in 1..nBits {
150-
set bits += [GenerateRandomBit()];
151-
}
152-
let sample = ResultArrayAsInt(bits);
139+
// Generate random number in the 0..max range.
140+
return GenerateRandomNumberInRange(max);
141+
}
153142
154-
// Return random number if it is within the requested range.
155-
// Generate it again if it is outside the range.
156-
return sample > max ? GenerateRandomNumberInRange(max) | sample;
143+
/// Generates a random number between 0 and `max`.
144+
operation GenerateRandomNumberInRange(max : Int) : Int {
145+
// Determine the number of bits needed to represent `max` and store it
146+
// in the `nBits` variable. Then generate `nBits` random bits which will
147+
// represent the generated random number.
148+
mutable bits = [];
149+
let nBits = BitSizeI(max);
150+
for idxBit in 1..nBits {
151+
set bits += [GenerateRandomBit()];
157152
}
153+
let sample = ResultArrayAsInt(bits);
158154
159-
operation GenerateRandomBit() : Result {
160-
// Allocate a qubit.
161-
use q = Qubit();
155+
// Return random number if it is within the requested range.
156+
// Generate it again if it is outside the range.
157+
return sample > max ? GenerateRandomNumberInRange(max) | sample;
158+
}
162159
163-
// Set the qubit into superposition of 0 and 1 using the Hadamard operation
164-
H(q);
160+
operation GenerateRandomBit() : Result {
161+
// Allocate a qubit.
162+
use q = Qubit();
165163
166-
// Measure the qubit value using the `M` operation, and store the
167-
// measurement value in the `result` variable.
168-
let result = M(q);
164+
// Set the qubit into superposition of 0 and 1 using the Hadamard operation
165+
H(q);
169166
170-
// Reset qubit to the |0〉 state.
171-
Reset(q);
167+
// Measure the qubit value using the `M` operation, and store the
168+
// measurement value in the `result` variable.
169+
let result = M(q);
172170
173-
// Return the result of the measurement.
174-
return result;
175-
}
171+
// Reset qubit to the |0〉 state.
172+
Reset(q);
173+
174+
// Return the result of the measurement.
175+
return result;
176+
}
176177
```
177178

178179
## Run the program

learn-pr/quantum/qsharp-create-first-quantum-development-kit/includes/6-summary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ In this module, we covered a lot. Here are a few key concepts to keep in mind:
1212

1313
## Next steps
1414

15-
The Quantum Development Kit includes a set of built-in Q# samples that you can use to learn more about Q# and quantum computing. To view the samples, open a blank Q# file in Visual Studio Code and type `sample`, then select the sample you want to view from the list of options. For example, you can find the Q# code we used in unit 2 by selecting *Random Bit sample*.
15+
The Quantum Development Kit includes a set of built-in Q# samples that you can use to learn more about Q# and quantum computing. To view the samples, open a blank Q# file in Visual Studio Code and type `sample`, then select the sample you want to view from the list of options. For example, you can find the Q# code we used in unit 2 by selecting the *Random Bits sample*.
1616

1717
## Learn more
1818

learn-pr/quantum/qsharp-create-first-quantum-development-kit/index.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ uid: learn.quantum.qsharp-create-first-quantum-development-kit
33
metadata:
44
title: Create your first Q# program by using the Azure Quantum Development Kit
55
description: Get started with Q# programming by building a quantum random number generator.
6-
ms.date: 01/22/2025
6+
ms.date: 06/05/2025
77
author: azure-quantum-content
88
ms.author: quantumdocwriters
99

0 commit comments

Comments
 (0)