62 of 151 menu

The seed method of the random module

The seed method of the random module initializes or stores a specific random number. The method uses the current system time of the OS to generate random numbers. The seed method is applied before the random method. The optional parameter of the method is a number for initialization or a kind of marking of the generated number. Therefore, when the random method is applied repeatedly, the generated number does not change. If the parameter is left empty, a new number will be generated each time.

Syntax

import random random.seed(number for marking)

Example

Let's initialize the number before generating it:

random.seed(5) print(random.random())

Result of code execution:

0.6229016948897019

Let's repeat the derivation of our number:

random.seed(5) print(random.random()) random.seed(5) print(random.random())

The result will remain the same:

0.6229016948897019 0.6229016948897019

See also

  • method random of module random,
    which returns a pseudo-random number
  • method uniform of module random,
    which generates a pseudo-random real number from the range
  • method randint of module random,
    which generates a pseudo-random integer from a range
  • method randrange of module random,
    which returns a random number from a range
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline