Getting started with Python using the seed () method

Source: Internet
Author: User
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 () 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:

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.

#!/usr/bin/pythonimport randomrandom.seed( 10 )print "Random number with seed 10 : ", random.random()# It will generate same random numberrandom.seed( 10 )print "Random number with seed 10 : ", random.random()# It will generate same random numberrandom.seed( 10 )print "Random number with seed 10 : ", random.random()

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

Random number with seed 10 : 0.57140259469Random number with seed 10 : 0.57140259469Random number with seed 10 : 0.57140259469

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.