@@ -68,7 +68,9 @@ cdef extern from "distributions.h":
6868
6969 cdef void entropy_init (aug_state * state ) nogil
7070
71- cdef double random_standard_uniform (aug_state * state ) nogil
71+ cdef float random_standard_uniform32 (aug_state * state ) nogil
72+
73+ cdef double random_standard_uniform64 (aug_state * state ) nogil
7274 cdef double random_gauss (aug_state * state ) nogil
7375 cdef double random_gauss_zig (aug_state * state ) nogil
7476 cdef double random_gauss_zig_julia (aug_state * state ) nogil
@@ -114,7 +116,8 @@ cdef extern from "distributions.h":
114116 cdef void random_bounded_uint16_fill (aug_state * state , uint16_t off , uint16_t rng , intptr_t cnt , uint16_t * out ) nogil
115117 cdef void random_bounded_uint8_fill (aug_state * state , uint8_t off , uint8_t rng , intptr_t cnt , uint8_t * out ) nogil
116118 cdef void random_bounded_bool_fill (aug_state * state , np .npy_bool off , np .npy_bool rng , intptr_t cnt , np .npy_bool * out ) nogil
117- cdef void random_uniform_fill (aug_state * state , intptr_t cnt , double * out ) nogil
119+ cdef void random_uniform_fill32 (aug_state * state , intptr_t cnt , double * out ) nogil
120+ cdef void random_uniform_fill64 (aug_state * state , intptr_t cnt , double * out ) nogil
118121 cdef void random_standard_exponential_fill (aug_state * state , intptr_t count , double * out ) nogil
119122 cdef void random_gauss_fill (aug_state * state , intptr_t count , double * out ) nogil
120123 cdef void random_gauss_zig_julia_fill (aug_state * state , intptr_t count , double * out ) nogil
@@ -680,7 +683,7 @@ cdef class RandomState:
680683 self .get_state ())
681684
682685 # Basic distributions:
683- def random_sample (self , size = None ):
686+ def random_sample (self , size = None , dtype = np . float64 ):
684687 """
685688 random_sample(size=None)
686689
@@ -698,6 +701,9 @@ cdef class RandomState:
698701 Output shape. If the given shape is, e.g., ``(m, n, k)``, then
699702 ``m * n * k`` samples are drawn. Default is None, in which case a
700703 single value is returned.
704+ dtype : dtype, optional
705+ Desired dtype of the result, either np.float64 (default)
706+ or np.float32.
701707
702708 Returns
703709 -------
@@ -722,7 +728,12 @@ cdef class RandomState:
722728 [-1.23204345, -1.75224494]])
723729
724730 """
725- return double_fill (& self .rng_state , & random_uniform_fill , size , self .lock )
731+ if dtype is np .float64 :
732+ return double_fill (& self .rng_state , & random_uniform_fill64 , size , self .lock )
733+ elif dtype is np .float32 :
734+ return float_fill (& self .rng_state , & random_uniform_fill32 , size , self .lock )
735+ else :
736+ raise ValueError ('Unknown dtype' )
726737
727738 def tomaxint (self , size = None ):
728739 """
0 commit comments