Ask Your Question

Revision history [back]

A computer can not create randomness out of nothing. To build pseudo-random numbers, it needs to start from a "seed", which is assumed to be random. Iy you do (it is usually built from e.g. the keys you hit on the keyboard, the webpages the browser visited, etc), and the use some algorithm to provide a lot of pseudo-random numbers from the randomness provided by the seed.

Fixing a seed allows you to start from something you control, and then being able to reproduce your tests. If you fix twice the same seed, you will get the same sequence of pseudo-random numbers.

sage: gaussian.set_seed(0.0)                                              
sage: gaussian.get_random_element()
0.100438956089
sage: gaussian.get_random_element()
-0.0660757438736
sage: gaussian.get_random_element()
1.25580630469
sage: gaussian.set_seed(0.0)       
sage: gaussian.get_random_element()
0.100438956089
sage: gaussian.get_random_element()
-0.0660757438736
sage: gaussian.get_random_element()
1.25580630469

If you want to write tests that need to output the same result along the time, use a fixed seed. If you want to make independent tests, don't !

A computer can not create randomness out of nothing. To build pseudo-random numbers, it needs to start from a "seed", which is assumed to be random. Iy If you do (it is usually built from e.g. not provide a seed, the computer will try to forge a seed that looks random, for example it will look at the keys you hit on the keyboard, the webpages the that your web browser visited, etc), etc, and the build a seed from that. Now, given a seed, it will use some algorithm to provide a lot of pseudo-random numbers, the randomness of this sequence of numbers from the randomness will be provided by the seed.seed (an algorithm can not create randomness out of nothing).

Fixing a seed allows you to start from something you control, and then being able to reproduce your tests. If you fix twice the same seed, you will get the same sequence of pseudo-random numbers.

sage: gaussian.set_seed(0.0)                                              
sage: gaussian.get_random_element()
0.100438956089
sage: gaussian.get_random_element()
-0.0660757438736
sage: gaussian.get_random_element()
1.25580630469
sage: gaussian.set_seed(0.0)       
sage: gaussian.get_random_element()
0.100438956089
sage: gaussian.get_random_element()
-0.0660757438736
sage: gaussian.get_random_element()
1.25580630469

If you want to write tests that need to output the same result along the time, use a fixed seed. If you want to make independent tests, don't !

A computer can not create randomness out of nothing. To build pseudo-random numbers, it needs to start from a "seed", which is assumed to be random. If you do not provide a seed, the computer will try to forge a seed that looks random, for example it will look at the keys you hit on the keyboard, the webpages that your web browser visited, etc, and build a seed from that. Now, given a seed, it will use some algorithm to provide a lot of pseudo-random numbers, the randomness of this sequence of numbers will be provided by the seed (an algorithm can not create randomness out of nothing).

Fixing a seed allows you to start from something you control, and then being able to reproduce your tests. tests (both the seed and the algorithm are deterministic). If you fix twice the same seed, you will get twice the same sequence of pseudo-random numbers.numbers:

sage: variance = 0.75
sage: gaussian = RealDistribution('gaussian', variance)
sage: gaussian.set_seed(0.0)                    
sage: gaussian.get_random_element()
0.100438956089
sage: gaussian.get_random_element()
-0.0660757438736
sage: gaussian.get_random_element()
1.25580630469
sage: gaussian.set_seed(0.0)       
gaussian.set_seed(0.0)
sage: gaussian.get_random_element()
0.100438956089
sage: gaussian.get_random_element()
-0.0660757438736
sage: gaussian.get_random_element()
1.25580630469

If you want to write tests that need to output the same result along the time, use a fixed seed. If you want to make independent tests, don't !

A computer can not create randomness out of nothing. To build pseudo-random numbers, it needs to start from a "seed", which is assumed to be random. If you do not provide a seed, the computer will try to forge a seed that looks random, for example it will look at the keys you hit on the keyboard, the webpages that your web browser visited, the date, etc, and build a seed from that. Now, given a seed, it will use some algorithm to provide a lot of pseudo-random numbers, the randomness of this sequence of numbers will be provided by the seed (an algorithm can not create randomness out of nothing).

Fixing a seed allows you to start from something you control, and then being able to reproduce your tests (both the seed and the algorithm are deterministic). If you fix twice the same seed, you will get twice the same sequence of pseudo-random numbers:

sage: variance = 0.75
sage: gaussian = RealDistribution('gaussian', variance)
sage: gaussian.set_seed(0.0)                   
sage: gaussian.get_random_element()
0.100438956089
sage: gaussian.get_random_element()
-0.0660757438736
sage: gaussian.get_random_element()
1.25580630469
sage: gaussian.set_seed(0.0)
sage: gaussian.get_random_element()
0.100438956089
sage: gaussian.get_random_element()
-0.0660757438736
sage: gaussian.get_random_element()
1.25580630469

If you want to write tests that need to output the same result along the time, use a fixed seed. If you want to make independent tests, don't !

A computer can not create randomness out of nothing. To build pseudo-random numbers, it needs to start from a "seed", which is assumed to be random. If you do not provide a seed, the computer will try to forge a seed that looks random, for example it will look at the keys you hit on the keyboard, the webpages that your web browser visited, the date, etc, and build a seed from that. Now, given a seed, it will use some algorithm to provide a lot of pseudo-random numbers, the randomness of this sequence of numbers will be provided by depend on the seed (an algorithm can not create randomness out of nothing).

Fixing a seed allows you to start from something you control, and then being able to reproduce your tests (both the seed and the algorithm are deterministic). If you fix twice the same seed, you will get twice the same sequence of pseudo-random numbers:

sage: variance = 0.75
sage: gaussian = RealDistribution('gaussian', variance)
sage: gaussian.set_seed(0.0)                   
sage: gaussian.get_random_element()
0.100438956089
sage: gaussian.get_random_element()
-0.0660757438736
sage: gaussian.get_random_element()
1.25580630469
sage: gaussian.set_seed(0.0)
sage: gaussian.get_random_element()
0.100438956089
sage: gaussian.get_random_element()
-0.0660757438736
sage: gaussian.get_random_element()
1.25580630469

If you want to write tests that need to output the same result along the time, use a fixed seed. If you want to make independent tests, don't !

A computer can not create randomness out of nothing. To build pseudo-random numbers, it needs to start from a "seed", which is assumed to be random. If you do not provide a seed, the computer will try to forge a seed that looks random, for example it will look at the keys you hit on the keyboard, the webpages that your web browser visited, the date, etc, and build a seed from that. Now, given a seed, it will use some algorithm to provide a lot of pseudo-random numbers, the randomness of this sequence of numbers will depend on the seed (an algorithm can not create randomness out of nothing).

Fixing a seed allows you to start from something you control, control completely, and then being able to reproduce your tests (both the seed and the algorithm are deterministic). If you fix twice the same seed, you will get twice the same sequence of pseudo-random numbers:

sage: variance = 0.75
sage: gaussian = RealDistribution('gaussian', variance)
sage: gaussian.set_seed(0.0)                   
sage: gaussian.get_random_element()
0.100438956089
sage: gaussian.get_random_element()
-0.0660757438736
sage: gaussian.get_random_element()
1.25580630469
sage: gaussian.set_seed(0.0)
sage: gaussian.get_random_element()
0.100438956089
sage: gaussian.get_random_element()
-0.0660757438736
sage: gaussian.get_random_element()
1.25580630469

If you want to write tests that need to output the same result along the time, use a fixed seed. If you want to make independent tests, don't !

A computer can not create randomness out of nothing. To build pseudo-random numbers, it needs to start from a "seed", which is assumed to be random. If you do not provide a seed, the computer will try to forge a seed that looks random, for example it will look at the keys you hit on the keyboard, the webpages that your web browser visited, the date, etc, and build a seed from that. Now, given a seed, it will use some algorithm to provide a lot of pseudo-random numbers, the randomness of this sequence of numbers will depend on the seed (an algorithm can not create randomness out of nothing).

Fixing a seed allows you to start from something you control completely, and then being able to reproduce your tests (both the seed (the seed is fixed and the algorithm are is deterministic). If you fix twice the same seed, you will get twice the same sequence of pseudo-random numbers:

sage: variance = 0.75
sage: gaussian = RealDistribution('gaussian', variance)
sage: gaussian.set_seed(0.0)                   
sage: gaussian.get_random_element()
0.100438956089
sage: gaussian.get_random_element()
-0.0660757438736
sage: gaussian.get_random_element()
1.25580630469
sage: gaussian.set_seed(0.0)
sage: gaussian.get_random_element()
0.100438956089
sage: gaussian.get_random_element()
-0.0660757438736
sage: gaussian.get_random_element()
1.25580630469

If you want to write tests that need to output the same result along the time, use a fixed seed. If you want to make independent tests, don't !

A computer can not create randomness out of nothing. To build pseudo-random numbers, it needs to start from a "seed", which is assumed to be random. If you do not provide a seed, the computer will try to forge a seed that looks random, for example it will look at the keys you hit on the keyboard, the webpages that your web browser visited, the date, etc, and build a seed from that. Now, given a seed, it will use some algorithm to provide a lot of pseudo-random numbers, the randomness of this sequence of numbers will depend on the seed (an algorithm can not create randomness out of nothing).

Fixing a seed allows you to start from something you control completely, and then being able to reproduce your tests (the seed is fixed and the algorithm is deterministic). If you fix twice the same seed, you will get twice the same sequence of pseudo-random numbers:

sage: variance = 0.75
sage: gaussian = RealDistribution('gaussian', variance)
sage: gaussian.set_seed(0.0)                   
sage: gaussian.get_random_element()
0.100438956089
sage: gaussian.get_random_element()
-0.0660757438736
sage: gaussian.get_random_element()
1.25580630469
sage: gaussian.set_seed(0.0)
sage: gaussian.get_random_element()
0.100438956089
sage: gaussian.get_random_element()
-0.0660757438736
sage: gaussian.get_random_element()
1.25580630469

Now, if you do not fix a seed, and do the following from two different sage sessions, you should get different values:

sage: variance = 0.75
sage: gaussian = RealDistribution('gaussian', variance)
sage: gaussian.get_random_element()
# random number that depends on the seed that is built according to the state of your computer.

If you want to write tests that need to output the same result along the time, use a fixed seed. If you want to make independent tests, don't !

A computer can not create randomness out of nothing. To build pseudo-random numbers, it needs to start from a "seed", which is assumed to be random. If you do not provide a seed, the computer will try to forge a seed that looks random, for example it will look at the keys you hit on the keyboard, the webpages that your web browser visited, the date, etc, and build a seed from that. Now, given a seed, it will use some algorithm to provide a lot of pseudo-random numbers, the randomness of this sequence of numbers will depend on the seed (an (a determiistic algorithm can not create randomness out of nothing).

Fixing a seed allows you to start from something you control completely, and then being be able to reproduce your tests (the seed is fixed and the algorithm is deterministic). If you fix twice the same seed, you will get twice the same sequence of pseudo-random numbers:

sage: variance = 0.75
sage: gaussian = RealDistribution('gaussian', variance)
sage: gaussian.set_seed(0.0)                   
sage: gaussian.get_random_element()
0.100438956089
sage: gaussian.get_random_element()
-0.0660757438736
sage: gaussian.get_random_element()
1.25580630469
sage: gaussian.set_seed(0.0)
sage: gaussian.get_random_element()
0.100438956089
sage: gaussian.get_random_element()
-0.0660757438736
sage: gaussian.get_random_element()
1.25580630469

Now, if you do not fix a seed, and do the following from two different sage sessions, you should get different values:

sage: variance = 0.75
sage: gaussian = RealDistribution('gaussian', variance)
sage: gaussian.get_random_element()
# random number that depends on the seed that is built 
# according to the state of your computer.

If you want to write tests that need to output the same result along the time, use a fixed seed. If you want to make independent tests, don't !