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

Function default_rng

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

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