The Quantum Exact Simulation Toolkit v4.0.0
Loading...
Searching...
No Matches

Functions for seeding QuEST's random generators. More...

Functions

int getNumSeeds ()
 
std::vector< unsigned > getSeeds ()
 
void getSeeds (unsigned *seeds)
 
void setSeeds (std::vector< unsigned > seeds)
 
void setSeeds (unsigned *seeds, int numSeeds)
 
void setSeedsToDefault ()
 

Detailed Description

Functions for seeding QuEST's random generators.

Re-seeding with identical seeds will determine all of QuEST's subsequent random outputs (such as measurement and random state preparation), and can be done at any stage of execution. When seeding is not explicitly performed, QuEST will attempt to use a cryptographically secure pseudorandom number generator (CSPRNG) if locally available, else fall back to a standard PRNG, via using the standard C++ random_device class.

Function Documentation

◆ getNumSeeds()

int getNumSeeds ( )
Note
Documentation for this function or struct is under construction!

Definition at line 52 of file debug.cpp.

52 {
53 validate_envIsInit(__func__);
54
55 return rand_getNumSeeds();
56}

Referenced by getSeeds().

◆ getSeeds() [1/2]

std::vector< unsigned > getSeeds ( )
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!
Note
Documentation for this function or struct is under construction!
Remarks
This function is only available in C++.

Definition at line 197 of file debug.cpp.

197 {
198 validate_envIsInit(__func__);
199
200 // allocate temp vector, and pedantically validate successful
201 vector<unsigned> out;
202 int numSeeds = getNumSeeds();
203 auto callback = [&]() { validate_tempAllocSucceeded(false, numSeeds, sizeof(unsigned), __func__); };
204 util_tryAllocVector(out, numSeeds, callback);
205
206 getSeeds(out.data());
207 return out;
208}
vector< unsigned > getSeeds()
Definition debug.cpp:197
int getNumSeeds()
Definition debug.cpp:52

Referenced by getSeeds(), and setRandomTestStateSeeds().

◆ getSeeds() [2/2]

void getSeeds ( unsigned * seeds)
Note
Documentation for this function or struct is under construction!

Definition at line 58 of file debug.cpp.

58 {
59 validate_envIsInit(__func__);
60
61 auto vec = rand_getSeeds();
62 auto num = rand_getNumSeeds();
63
64 for (int i=0; i<num; i++)
65 seeds[i] = vec[i];
66}

◆ setSeeds() [1/2]

void setSeeds ( std::vector< unsigned > seeds)
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!
Note
Documentation for this function or struct is under construction!
Remarks
This function is only available in C++.

◆ setSeeds() [2/2]

void setSeeds ( unsigned * seeds,
int numSeeds )
Note
Documentation for this function or struct is under construction!

Definition at line 37 of file debug.cpp.

37 {
38 validate_envIsInit(__func__);
39 validate_randomSeeds(seeds, numSeeds, __func__);
40
41 // consults only root-node seeds
42 rand_setSeeds(vector<unsigned>(seeds, seeds+numSeeds));
43}

Referenced by setRandomTestStateSeeds().

◆ setSeedsToDefault()

void setSeedsToDefault ( )
Note
Documentation for this function or struct is under construction!

Definition at line 45 of file debug.cpp.

45 {
46 validate_envIsInit(__func__);
47
48 rand_setSeedsToDefault();
49}