# randomly create a 2-dimensional quantum state
from random import randrange
def random_quantum_state():
    first_entry = randrange(101)
    first_entry = first_entry/100
    first_entry = first_entry**0.5 
    if randrange(2) == 0: 
        first_entry = -1 * first_entry
    second_entry = 1 - (first_entry**2)
    second_entry = second_entry**0.5
    if randrange(2) == 0: 
        second_entry = -1 * second_entry
    return [first_entry,second_entry]

%run qlatvia.py

draw_qubit()

from math import acos, pi

# randomly picking 6 quantum states
for i in range(6): 
    [x,y]=random_quantum_state() # picking a quantum state 
    angle_radian = acos(x) # radian of the angle with state |0>
    angle_degree = 360*angle_radian/(2*pi) # degree of the angle with state |0>
    state_name='|v'+str(i)+'>' # giving a name to the quantum state
    draw_quantum_state(x,y,state_name) # drawing the quantum state
    print(state_name,'has degree of',angle_degree,"with state |0>") # print the degree of angle with state |0>

# randomly create a 2-dimensional quantum state
from random import randrange
def random_quantum_state():
    first_entry = randrange(101)
    first_entry = first_entry/100
    first_entry = first_entry**0.5 
    if randrange(2) == 0: 
        first_entry = -1 * first_entry
    second_entry = 1 - (first_entry**2)
    second_entry = second_entry**0.5
    if randrange(2) == 0: 
        second_entry = -1 * second_entry
    return [first_entry,second_entry]

# finding the angle of a 2-dimensional quantum state
from math import acos, pi
def angle_quantum_state(x,y):
    angle_radian = acos(x) # radian of the angle with state |0>
    angle_degree = 360*angle_radian/(2*pi) # degree of the angle with state |0>
    # if the second amplitude is negative, 
    #     then angle is (-angle_degree)
    #     or equivalently 360 + (-angle_degree)
    if y<0: angle_degree = 360-angle_degree # degree of the angle
    # else degree of the angle is the same as degree of the angle with state |0>
    return angle_degree

%run qlatvia.py

draw_qubit()

from math import acos, pi

# randomly picking 6 quantum states
for i in range(4): 
    [x,y]=random_quantum_state() # picking a quantum state 
    angle_degree = angle_quantum_state(x,y)
    state_name='|v'+str(i)+'>' # giving a name to the quantum state
    draw_quantum_state(x,y,state_name) # drawing the quantum state
    print(state_name,'has degree of',angle_degree) # print the degree of angle

