# How to initialize a random state in Qiskit?

I know I can make a random_circuit, but I see that Qiskit has random_statevector. I'd like to optimize computation time by initializing a state by that instead of putting a random circuit at the beginning. Is it possible and how do I do it? Thank you!

here is an example of how to initialize the random statevector then send it to the quantum circuit:

from qiskit.quantum_info import random_statevector, Statevector
from qiskit import QuantumCircuit
# import numpy as np

vec = random_statevector(2)
# vec = Statevector([1, 0])
print('before circuit: {}'.format(vec))

qc = QuantumCircuit(1)
qc.x(0)
qc.draw()

new_vec = vec.evolve(qc)
print('after circuit: {}'.format(new_vec))


you should notice that the dim of state vector is 2 so the quantum circuit is 1 qubit.

How about using the data attribute, like this:

qc = QuantumCircuit(1)
initial_state = qc.initialize(random_statevector(2).data, 0)