import numpy as np


def read(state, shots, rng):
    """Prépare et lit l'état `shots` fois ; renvoie les counts."""
    zeros = int(np.sum(rng.random(shots) < state[0] ** 2))
    return {"0": zeros, "1": shots - zeros}


plus = np.array([1.0, 1.0]) / np.sqrt(2)
minus = np.array([1.0, -1.0]) / np.sqrt(2)

print("probabilités |+⟩ :", np.round(plus**2, 3))
print("probabilités |−⟩ :", np.round(minus**2, 3))

rng = np.random.default_rng(42)
print("1 000 lectures de |+⟩ :", read(plus, 1000, rng))
print("1 000 lectures de |−⟩ :", read(minus, 1000, rng))
