MCPcopy Create free account
hub / github.com/dask/dask / default_rng

Function default_rng

dask/array/random.py:392–484  ·  view source on GitHub ↗

Construct a new Generator with the default BitGenerator (PCG64). Parameters ---------- seed : {None, int, array_like[ints], SeedSequence, BitGenerator, Generator}, optional A seed to initialize the `BitGenerator`. If None, then fresh, unpredictable entropy will be p

(seed=None)

Source from the content-addressed store, hash-verified

390
391
392def default_rng(seed=None):
393 """
394 Construct a new Generator with the default BitGenerator (PCG64).
395
396 Parameters
397 ----------
398 seed : {None, int, array_like[ints], SeedSequence, BitGenerator, Generator}, optional
399 A seed to initialize the `BitGenerator`. If None, then fresh,
400 unpredictable entropy will be pulled from the OS. If an ``int`` or
401 ``array_like[ints]`` is passed, then it will be passed to
402 `SeedSequence` to derive the initial `BitGenerator` state. One may
403 also pass in a `SeedSequence` instance.
404 Additionally, when passed a `BitGenerator`, it will be wrapped by
405 `Generator`. If passed a `Generator`, it will be returned unaltered.
406
407 Returns
408 -------
409 Generator
410 The initialized generator object.
411
412 Notes
413 -----
414 If ``seed`` is not a `BitGenerator` or a `Generator`, a new
415 `BitGenerator` is instantiated. This function does not manage a default
416 global instance.
417
418 Examples
419 --------
420 ``default_rng`` is the recommended constructor for the random number
421 class ``Generator``. Here are several ways we can construct a random
422 number generator using ``default_rng`` and the ``Generator`` class.
423
424 Here we use ``default_rng`` to generate a random float:
425
426 >>> import dask.array as da
427 >>> rng = da.random.default_rng(12345)
428 >>> print(rng)
429 Generator(PCG64)
430 >>> rfloat = rng.random().compute()
431 >>> rfloat
432 array(0.86999885)
433 >>> type(rfloat)
434 <class 'numpy.ndarray'>
435
436 Here we use ``default_rng`` to generate 3 random integers between 0
437 (inclusive) and 10 (exclusive):
438
439 >>> import dask.array as da
440 >>> rng = da.random.default_rng(12345)
441 >>> rints = rng.integers(low=0, high=10, size=3).compute()
442 >>> rints
443 array([2, 8, 7])
444 >>> type(rints[0])
445 <class 'numpy.int64'>
446
447 Here we specify a seed so that we have reproducible results:
448
449 >>> import dask.array as da

Callers 1

compression_matrixFunction · 0.90

Calls 2

GeneratorClass · 0.70
default_bit_generatorMethod · 0.45

Tested by

no test coverage detected