@@ -181,13 +181,13 @@ def load_cache(self, bitstring: str, flush: bool = False) -> None:
181181 self .bitcache .flush ()
182182 self .bitcache .push (bitstring )
183183
184- def random_bitstring (self , num_bits : int = 0 ) -> str :
184+ def random_bitstring (self , num_bits : Optional [ int ] = None ) -> str :
185185 """
186186 Returns a random bitstring of a given lenght.
187187
188188 Parameters
189189 ----------
190- num_bits: int, default: 0
190+ num_bits: int, optional
191191 Number of bits to retrieve. If less than one it defaults to the raw
192192 number of BITS for the instance QuantumBitGenerator (i.e. 32 or 64).
193193
@@ -196,8 +196,11 @@ def random_bitstring(self, num_bits: int = 0) -> str:
196196 out: str
197197 Bitstring of lenght `num_bits`.
198198 """
199- if num_bits < 1 :
200- num_bits = self .BITS
199+ num_bits = (
200+ num_bits
201+ if num_bits and type (num_bits ) is int and num_bits > 0
202+ else self .BITS
203+ )
201204 while self .bitcache .size < num_bits :
202205 self ._refill_cache ()
203206 return self .bitcache .pop (num_bits )
@@ -232,13 +235,13 @@ def random_double(self, n: float = 1) -> float:
232235 value : float = unpack ("d" , packed )[0 ] - 1.0
233236 return value * n
234237
235- def random_uint (self , num_bits : int = 0 ) -> int :
238+ def random_uint (self , num_bits : Optional [ int ] = None ) -> int :
236239 """
237240 Returns a random unsigned int of a given size in bits.
238241
239242 Parameters
240243 ----------
241- num_bits: int, default: 0
244+ num_bits: int, optional
242245 Number of bits to retrieve. If less than one it defaults to the raw
243246 number of BITS for the instance QuantumBitGenerator (i.e. 32 or 64).
244247
@@ -247,8 +250,11 @@ def random_uint(self, num_bits: int = 0) -> int:
247250 out: int
248251 Unsigned int of `num_bits` bits.
249252 """
250- if num_bits < 1 :
251- num_bits = self .BITS
253+ num_bits = (
254+ num_bits
255+ if num_bits and type (num_bits ) is int and num_bits > 0
256+ else self .BITS
257+ )
252258 return int (self .random_bitstring (num_bits ), 2 )
253259
254260 ############################### PRIVATE API ###############################
0 commit comments