Getting started with Python using the seed () method

Source: Internet
Author: User

Getting started with Python using the seed () method

This article describes how to use the seed () method in basic Python basics. It is the basic knowledge of Python learning. For more information, see

 

 

Seed () is used to set the start value of the integer used to generate a random number. Call this function before calling any other functions of the random module.
Syntax

The syntax of the seed () method is as follows:

?

1

Seed ([x])

Note: This function cannot be directly accessed. Therefore, you need to import the seed module and then use the random static object to call this function.
Parameters

  • X -- this is the seed of the next random number. If this parameter is omitted, the system time is required to generate the next random number.

Return Value

This method does not return any value.
Example

The following example shows how to use the seed () method.

?

1

2

3

4

5

6

7

8

9

10

11

12

13

#! /Usr/bin/python

Import random

 

Random. seed (10)

Print "Random number with seed 10:", random. random ()

 

# It will generate same random number

Random. seed (10)

Print "Random number with seed 10:", random. random ()

 

# It will generate same random number

Random. seed (10)

Print "Random number with seed 10:", random. random ()

When we run the above program, it will produce the following results:

?

1

2

3

Random number with seed 10: 0.57140259469

Random number with seed 10: 0.57140259469

Random number with seed 10: 0.57140259469

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.