Python Random getrandbits() Method

❮ Random Methods


Example

Return an 8 bits sized integer:

import random

print(random.getrandbits(8))
Try it Yourself »

Definition and Usage

The getrandbits() method returns an integer in the specified size (in bits).


Syntax

random.getrandbits(n)

Parameter Values

Parameter Description
n Required. A number specifying the size, in bits, of the returned integer.

❮ Random Methods

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.