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

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

The getstate() method returns an object containing the random number generator’s current state.<\/p>\n

Use this method to capture the state, and then use the setstate() method to restore the state using the captured state.<\/p>\n

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

random.getstate()<\/pre>\n

Parameters: <\/strong>This method doesn’t accept any parameters.<\/p>\n

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

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

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

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

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

The random value =  90\r\nThe random value =  90<\/pre>\n

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

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

Given list = [4, 6, 7, 9]<\/pre>\n

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

The random value = 7\r\nThe random value = 7<\/pre>\n

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