Movatterモバイル変換


[0]ホーム

URL:


SciPy

numpy.random.random_integers

numpy.random.random_integers(low,high=None,size=None)

Random integers of type np.int betweenlow andhigh, inclusive.

Return random integers of type np.int from the “discrete uniform”distribution in the closed interval [low,high]. Ifhigh isNone (the default), then results are from [1,low]. The np.inttype translates to the C long type used by Python 2 for “short”integers and its precision is platform dependent.

This function has been deprecated. Use randint instead.

Deprecated since version 1.11.0.

Parameters:

low : int

Lowest (signed) integer to be drawn from the distribution (unlesshigh=None, in which case this parameter is thehighest suchinteger).

high : int, optional

If provided, the largest (signed) integer to be drawn from thedistribution (see above for behavior ifhigh=None).

size : int or tuple of ints, optional

Output shape. If the given shape is, e.g.,(m,n,k), thenm*n*k samples are drawn. Default is None, in which case asingle value is returned.

Returns:

out : int or ndarray of ints

size-shaped array of random integers from the appropriatedistribution, or a single such random int ifsize not provided.

See also

random.randint
Similar torandom_integers, only for the half-open interval [low,high), and 0 is the lowest value ifhigh is omitted.

Notes

To sample from N evenly spaced floating-point numbers between a and b,use:

a+(b-a)*(np.random.random_integers(N)-1)/(N-1.)

Examples

>>>np.random.random_integers(5)4>>>type(np.random.random_integers(5))<type 'int'>>>>np.random.random_integers(5,size=(3,2))array([[5, 4],       [3, 3],       [4, 5]])

Choose five random numbers from the set of five evenly-spacednumbers between 0 and 2.5, inclusive (i.e., from the set{0, 5/8, 10/8, 15/8, 20/8}):

>>>2.5*(np.random.random_integers(5,size=(5,))-1)/4.array([ 0.625,  1.25 ,  0.625,  0.625,  2.5  ])

Roll two six sided dice 1000 times and sum the results:

>>>d1=np.random.random_integers(1,6,1000)>>>d2=np.random.random_integers(1,6,1000)>>>dsums=d1+d2

Display results as a histogram:

>>>importmatplotlib.pyplotasplt>>>count,bins,ignored=plt.hist(dsums,11,normed=True)>>>plt.show()

(Source code,png,pdf)

../../_images/numpy-random-random_integers-1.png

Previous topic

numpy.random.randint

Next topic

numpy.random.random_sample

  • © Copyright 2008-2009, The Scipy community.
  • Last updated on Jun 10, 2017.
  • Created usingSphinx 1.5.3.

[8]ページ先頭

©2009-2025 Movatter.jp