{"id":25486,"date":"2021-11-16T08:40:01","date_gmt":"2021-11-16T03:10:01","guid":{"rendered":"https:\/\/python-programs.com\/?p=25486"},"modified":"2021-11-16T08:40:01","modified_gmt":"2021-11-16T03:10:01","slug":"python-random-setstate-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-random-setstate-method-with-examples\/","title":{"rendered":"Python Random setstate() Method with Examples"},"content":{"rendered":"

random setstate() Method in Python:<\/strong><\/p>\n

The setstate() method is used to return the random number generator’s state back to the specified state.<\/p>\n

To capture the state, use the getstate() method.<\/p>\n

Syntax:<\/strong><\/p>\n

random.setstate(state)<\/pre>\n

Parameters<\/strong><\/p>\n

state:<\/strong> This is Required. It is a state object. The setstate() method returns the random number generator’s state to this state.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given list = [10, 40, 60, 80, 90]\r\nGiven length = 2<\/pre>\n

Output:<\/strong><\/p>\n

[10, 80]\r\n[10, 80]<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given list = [25, 35, 9, 45, 65]\r\nGiven length = 3<\/pre>\n

Output:<\/strong><\/p>\n

[45, 35, 65]\r\n[45, 35, 65]<\/pre>\n

Random setstate() Method with Examples in Python<\/h2>\n