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

Function default_rng

dask/array/random.py:396–488  ·  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

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