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

In Python, the random module is used to generate random numbers. This is not truly random; rather, it is used to generate pseudo-random numbers. This implies that these numbers can be determined at random.<\/p>\n

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

getrandbits() method returns an integer of the specified size (in bits).<\/p>\n

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

random.getrandbits(num)<\/pre>\n

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

num:<\/strong> This is Required. A number indicating the size of the returned integer in bits.<\/p>\n

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

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

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

Given number(size) = 6<\/pre>\n

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

The random integer =  56<\/pre>\n

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

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

Given number(size) = 10<\/pre>\n

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

The random integer = 59<\/pre>\n

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