random, seed(), setstate(), getstate()

Return a random number [0., 1.).

import random
print( random.random())

To generate the identical sequence of random numbers:

import random
print( random.seed( 1.753)
print( random.random())
print( random.seed( 1.753)
print( random.random())

If there are possible interferences with other parts of the program, the functions getstate() and setstate() may be helpful. getstate() returns an object capturing the full internal state of the generator, can be used with setstate().

The example below is taken from a VcExecutor. It was not possible to control the random number sequence with seed() alone.

#!/bin/env python
#
import HasyUtils
import random

class VC:
    def __init__(self):
        ...
        self.scanID = -1
    #
    # Counts
    #
    def read_Counts( self):
        #
        # reset things, if the ScanID changes, new scan
        #
        try:
            if int( HasyUtils.getEnv( 'ScanID')) != self.scanID:
                self.scanID = int( HasyUtils.getEnv( 'ScanID'))
                random.seed( 1.753)
                self.randomState = random.getstate()
        except: 
            pass
 
        argout = ...
            
        random.setstate( self.randomState)
        argout += 3.*random.random()
        self.randomState = random.getstate()
             
        return argout
    ...