This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GenerateRandomBit as before | |
operation GenerateRandomNumberInRange(max: Int): Int { | |
mutable bits = []; | |
let nBits = BitSizeI(max); | |
for idxBit in 1..nBits { | |
bits += [GenerateRandomBit()]; | |
} | |
let sample = ResultArrayAsInt(bits); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
operation GenerateRandomBit() : Result { | |
use q = Qubit(); | |
H(q); | |
let result = M(q); | |
Reset(q); | |
return result; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
simulator = cirq.Simulator() | |
def quantum_random_number_generator(nbits): | |
qubit = cirq.LineQubit(0) | |
circuit = cirq.Circuit(cirq.H(qubit), cirq.measure(qubit)) | |
simulation_result = simulator.run(circuit, repetitions=nbits) | |
measurements = simulation_result.measurements["q(0)"] | |
bits = ''.join([str(m) for m in measurements.flatten()]) | |
number = int(bits, 2) | |
print("Generated random number: ", bits, " -> ", number) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# quantum_random_number_generator as before | |
def generate_number(max): | |
nbits = math.floor(math.log(max) / math.log(2)) + 1 | |
while True: | |
number = quantum_random_number_generator(nbits) | |
if number < max: | |
return number |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
simulator = AerSimulator() | |
def quantum_random_number_generator(nbits): | |
qc = QuantumCircuit(1, 1) # One qubit and one classical bit | |
qc.h(0) | |
qc.measure(0, 0) # Measure the qubit and store the result in the classical bit | |
job = simulator.run(qc, shots=nbits, memory=True) | |
simulation_result = job.result() | |
measurements = simulation_result.get_memory() | |
bits = ''.join([str(m) for m in measurements]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class QuantumNumberGenerator: | |
// code shown before | |
private def generateNumberWithNBits(n: Int): Long = | |
(1 to n).foldLeft(0L) { case (acc, _) => | |
val bit = quantumRandomBitGeneration() | |
// shift the accumulator left by 1 position and add the new random bit to the least significant position | |
(acc << 1) | bit | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class QuantumNumberGenerator: | |
private val simulator = SimpleQuantumExecutionEnvironment() | |
private val program = Program(1, Step(Hadamard(0))) | |
private def quantumRandomBitGeneration(): Int = | |
val qubits = simulator.runProgram(program).getQubits | |
qubits(0).measure() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.flywaydb.core.Flyway | |
import scala.jdk.CollectionConverters._ | |
object FlywayMigrator { | |
def migrate(): Unit = { | |
val retries: Int = ??? | |
val eventsSchema: String = ??? | |
val defaultSchema: String = ??? | |
val placeholders: Map[String, String] = Map( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE USER IF NOT EXISTS `${user}`@`%` IDENTIFIED BY '${password}'; | |
GRANT Insert, Select ON `${event_schema}`.* TO `${user}`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE `${event_schema}`; | |
DROP TABLE IF EXISTS journal; | |
CREATE TABLE IF NOT EXISTS journal ( | |
ordering SERIAL, | |
persistence_id VARCHAR(255) NOT NULL, | |
sequence_number BIGINT NOT NULL, | |
deleted BOOLEAN DEFAULT FALSE NOT NULL, | |
tags VARCHAR(255) DEFAULT NULL, |
NewerOlder