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

Function default_rng

dask/array/_array_expr/random.py:378–470  ·  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

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

Callers

nothing calls this directly

Calls 2

GeneratorClass · 0.70
default_bit_generatorMethod · 0.45

Tested by

no test coverage detected