How to use the seed() method in Python

爱喝马黛茶的安东尼
Release: 2019-08-17 09:27:49
Original
5945 people have browsed it

How to use the seed() method in Python

How to use the seed() method in Python? The following is a relevant introduction to the seed() method:

Description

The seed() method changes the seed of the random number generator. This function can be called before calling other random module functions.

Syntax

The following is the syntax of the seed() method:

import random
random.seed ( [x] )
Copy after login

Note: seed() cannot be accessed directly and needs to import the random module , and then call this method through the random static object.

Related recommendations: "Python Video Tutorial"

Parameters

x -- Change the seed of the random number generator . If you don't understand the principle, you don't have to set the seed specifically, Python will choose the seed for you.

Return value

This function has no return value.

Example

The following shows an example of using the seed() method:

#!/usr/bin/python
# -*- coding: UTF-8 -*- 
import random
random.seed( 10 )
print "Random number with seed 10 : ", random.random()
# 生成同一个随机数
random.seed( 10 )
print "Random number with seed 10 : ", random.random()
# 生成同一个随机数
random.seed( 10 )
print "Random number with seed 10 : ", random.random()
Copy after login

The output result after running the above example is:

Random number with seed 10 :  0.57140259469
Random number with seed 10 :  0.57140259469
Random number with seed 10 :  0.57140259469
Copy after login

The above is the detailed content of How to use the seed() method in Python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!