ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_distUnif::setUnifRand Interface Reference

Return a uniform random scalar or contiguous array of arbitrary rank of randomly uniformly distributed discrete logical, integer, character value(s), or continuous real or `complex value(s) within the specified input range. More...

Detailed Description

Return a uniform random scalar or contiguous array of arbitrary rank of randomly uniformly distributed discrete logical, integer, character value(s), or continuous real or `complex value(s) within the specified input range.

Parameters
[in,out]rng: The input/output scalar of type,
  1. rngf_type, or
  2. splitmix64_type, or
  3. xoshiro256ssg_type,
  4. xoshiro256ssw_type,
containing the user-specified random number generator algorithm to be used.
The user must initialize the object with the corresponding type constructors if non-deterministic RNG are desired. (optional, default = rngf_type)
[out]rand: The output object of either
  1. scalar of type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) of arbitrary len type parameter or,
or contiguous array of the rank, shape, and size as other array-like arguments, of either
  1. type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) of arbitrary len type parameter or,
  2. type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64) or,
  3. type complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128) or,
  4. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128) or,
  5. type logical of kind any supported by the processor (e.g., LK),
containing the uniformly-distributed random output value.
  1. If rand is of type logical, its value is either .false. or .true..
  2. If rand is of type integer, its value is in the interval [lb, ub].
  3. If rand is of type complex or real, its value is in the interval [lb, ub).
  4. If rand is of type character, its value is by default in the interval [char(1), char(127)].
[in]lb: The input scalar (or array of the same rank, shape, and size as other array-like arguments), of the same type and kind as rand, representing the lower bound of the Uniform distribution.
  1. If rand is of type character, then len(rand) == len(lb) must hold.
  2. If rand is of type logical, then lb must be .false. (there is no other possibility).
(optional, default = char(1), repeat(char(1), len(rand)), -huge(rand), .false., (0.,0.), or 0., for a scalar character, vector character, integer, complex, or real output rand, respectively.
It must be present if and only if ub is also present.)
[in]ub: The input scalar (or array of the same shape as rand) of the same type and kind as rand, representing the upper bound of the Uniform distribution.
If rand is of type character, then len(rand) == len(ub) must hold.
If rand is of type logical, then ub does not exist as an input argument (it must not be present).
(optional, default = char(127), repeat(char(127), len(rand)), +huge(rand), .true., (1.,1.), or 1., for a scalar character, vector character, integer, complex, or real output rand, respectively.
It must be present if and only if ub is also present.)


Possible calling interfaces

call setUnifRand(rand) ! `rand` can be any intrinsic type: character, complex, logical, integer, real.
call setUnifRand(rand, lb, ub) ! `rand` can be any intrinsic type: character, complex, logical, integer, real.
call setUnifRand(rng, rand) ! `rand` can be any intrinsic type: character, complex, logical, integer, real.
call setUnifRand(rng, rand, lb, ub) ! `rand` can be any intrinsic type: character, complex, logical, integer, real.
!
Return a uniform random scalar or contiguous array of arbitrary rank of randomly uniformly distribute...
This module contains classes and procedures for computing various statistical quantities related to t...
Warning
The condition len(lb) == len(ub) .or. len(lb) == 1 .or. len(ub) == 1 for the corresponding input arguments of type character.
The condition lb <= ub must hold for the corresponding input arguments where logical values are compared by the procedures of module pm_logicalCompare and complex values are compared by the procedures of module pm_complexCompareAll.
These conditions are verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
Remarks
The procedures under discussion are impure. The procedures of this generic interface are pure when the argument rng is present.
The procedures under discussion are elemental. The procedures of this generic interface are non-elemental when the argument rng is present.
The procedures under this generic interface are carefully designed to avoid possible overflow due to specifying huge negative and positive lb and ub limits of type integer, complex, real.
This is possible at the cost of making the random number generation slightly more expensive (by a few CPU cycles, equivalent to and extra multiplication).
It is expected that the condition lb <= ub if the two input arguments are specified by the user.
However, this condition is neither enforced nor checked at runtime within the procedures.
Note
By default random characters are generated from the ASCII collating sequence to ensure portability across compilers and platforms.
If random uniform characters from the processor's collating sequence are desired, specify the lb and ub inputs argument as integers of default kind IK, such that the random numbers are generated from the processor-dependent character interval [char(lb), char(ub)].
See also
rngf
isHead
getUnifCDF
getUnifRand
setUnifRand
getUnifRandState
setUnifRandState
rngu_type
rngf_type
splitmix64_type
xoshiro256ssw_type
getUnifRandStateSize


Example usage

1program example
2
3 use pm_kind, only: SK, LK
4 use pm_kind, only: IK => IKS ! All other kinds are also supported.
5 use pm_kind, only: CK => CKS ! All other kinds are also supported.
6 use pm_kind, only: RK => RKS ! All other kinds are also supported.
7 use pm_io, only: display_type
8 use pm_distUnif, only: setUnifRand
9 use pm_io, only: getErrTableWrite
10
11 implicit none
12
13 integer(IK) , parameter :: NP = 5_IK
14
15 character(5,SK) :: rand_D0_SK
16 character(2,SK) :: rand_D1_SK(NP), rand_D2_SK(NP,NP)
17 logical(LK) :: rand_D0_LK, rand_D1_LK(NP), rand_D2_LK(NP,NP)
18 integer(IK) :: rand_D0_IK, rand_D1_IK(NP), rand_D2_IK(NP,NP)
19 complex(CK) :: rand_D0_CK, rand_D1_CK(NP), rand_D2_CK(NP,NP)
20 real(RK) :: rand_D0_RK, rand_D1_RK(NP), rand_D2_RK(NP,NP)
21
22 type(display_type) :: disp
23
24 disp = display_type(file = "main.out.F90")
25
26
27 call disp%skip()
28 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
29 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
30 call disp%show("! Generate `logical`-valued random numbers.")
31 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
32 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
33 call disp%skip()
34
35 call disp%skip()
36 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
37 call disp%show("! Generate a scalar logical random number.")
38 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
39 call disp%skip()
40
41 call disp%show("call setUnifRand(rand_D0_LK) ! random binary logical in the default range [.false._LK, .true._LK].")
42 call setUnifRand(rand_D0_LK)
43 call disp%show("rand_D0_LK")
44 call disp%show( rand_D0_LK )
45 call disp%skip()
46
47 call disp%skip()
48 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
49 call disp%show("! Generate a vector of logical random numbers.")
50 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
51 call disp%skip()
52
53 call disp%show("call setUnifRand(rand_D1_LK) ! random binary logical in the default range [.false._LK, .true._LK].")
54 call setUnifRand(rand_D1_LK)
55 call disp%show("rand_D1_LK")
56 call disp%show( rand_D1_LK )
57 call disp%skip()
58
59 call disp%skip()
60 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
61 call disp%show("! Generate a matrix of logical random numbers.")
62 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
63 call disp%skip()
64
65 call disp%show("call setUnifRand(rand_D2_LK) ! random binary integer in the default range [.false._LK, .true._LK].")
66 call setUnifRand(rand_D2_LK)
67 call disp%show("rand_D2_LK")
68 call disp%show( rand_D2_LK )
69 call disp%skip()
70
71
72 call disp%skip()
73 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
74 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
75 call disp%show("! Generate random `character` values.")
76 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
77 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
78 call disp%skip()
79
80 call disp%skip()
81 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
82 call disp%show("! Generate a scalar character random value.")
83 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
84 call disp%skip()
85
86 call disp%show("call setUnifRand(rand_D0_SK) ! random ASCII character in the default range [char(1), char(127)].")
87 call setUnifRand(rand_D0_SK)
88 call disp%show("rand_D0_SK")
89 call disp%show( rand_D0_SK , deliml = SK_"""" )
90 call disp%skip()
91
92 call disp%show("call setUnifRand(rand_D0_SK, lb = 'AA0aa', ub = 'ZZ9zz') ! random ASCII character in the range [""A"", ""z""].")
93 call setUnifRand(rand_D0_SK, lb = 'AA0aa', ub = 'ZZ9zz')
94 call disp%show("rand_D0_SK")
95 call disp%show( rand_D0_SK , deliml = SK_"""" )
96 call disp%skip()
97
98 call disp%skip()
99 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
100 call disp%show("! Generate a vector of character random values.")
101 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
102 call disp%skip()
103
104 call disp%show("call setUnifRand(rand_D1_SK) ! random ASCII character in the default range [char(1), char(127)].")
105 call setUnifRand(rand_D1_SK)
106 call disp%show("rand_D1_SK")
107 call disp%show( rand_D1_SK , deliml = SK_"""" )
108 call disp%skip()
109
110 call disp%show("call setUnifRand(rand_D1_SK, lb = 'Aa', ub = 'Zz') ! random ASCII character in the range [""Aa"", ""Zz""] for each character in string separately.")
111 call setUnifRand(rand_D1_SK, lb = 'Aa', ub = 'Zz')
112 call disp%show("rand_D1_SK")
113 call disp%show( rand_D1_SK , deliml = SK_"""" )
114 call disp%skip()
115
116 call disp%skip()
117 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
118 call disp%show("! Generate a matrix of character random values.")
119 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
120 call disp%skip()
121
122 call disp%show("call setUnifRand(rand_D2_SK) ! random ASCII character in the default range [char(1), char(127)].")
123 call setUnifRand(rand_D2_SK)
124 call disp%show("rand_D2_SK")
125 call disp%show( rand_D2_SK , deliml = SK_"""" )
126 call disp%skip()
127
128 call disp%show("call setUnifRand(rand_D2_SK, lb = 'aA', ub = 'zA') ! random ASCII character in the range [""aA"", ""zZ""] for each character in string separately.")
129 call setUnifRand(rand_D2_SK, lb = 'aA', ub = 'zA')
130 call disp%show("rand_D2_SK")
131 call disp%show( rand_D2_SK , deliml = SK_"""" )
132 call disp%skip()
133
134
135 call disp%skip()
136 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
137 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
138 call disp%show("! Generate `integer`-valued random numbers.")
139 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
140 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
141 call disp%skip()
142
143 call disp%skip()
144 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
145 call disp%show("! Generate a scalar integer random number.")
146 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
147 call disp%skip()
148
149 call disp%show("call setUnifRand(rand_D0_IK) ! random binary integer in the default range [0, 1].")
150 call setUnifRand(rand_D0_IK)
151 call disp%show("rand_D0_IK")
152 call disp%show( rand_D0_IK )
153 call disp%skip()
154
155 call disp%show("call setUnifRand(rand_D0_IK, -3_IK, 2_IK) ! random integer in range [-3 2].")
156 call setUnifRand(rand_D0_IK, -3_IK, 2_IK)
157 call disp%show("rand_D0_IK")
158 call disp%show( rand_D0_IK )
159 call disp%skip()
160
161 call disp%skip()
162 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
163 call disp%show("! Generate a vector of integer random numbers.")
164 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
165 call disp%skip()
166
167 call disp%show("call setUnifRand(rand_D1_IK) ! random binary integer in the default range [0, 1].")
168 call setUnifRand(rand_D1_IK)
169 call disp%show("rand_D1_IK")
170 call disp%show( rand_D1_IK )
171 call disp%skip()
172
173 call disp%show("call setUnifRand(rand_D1_IK, -3_IK, 2_IK) ! random integer in range [-3 2].")
174 call setUnifRand(rand_D1_IK, -3_IK, 2_IK)
175 call disp%show("rand_D1_IK")
176 call disp%show( rand_D1_IK )
177 call disp%skip()
178
179 call disp%skip()
180 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
181 call disp%show("! Generate a matrix of integer random numbers.")
182 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
183 call disp%skip()
184
185 call disp%show("call setUnifRand(rand_D2_IK) ! random binary integer in the default range [0, 1].")
186 call setUnifRand(rand_D2_IK)
187 call disp%show("rand_D2_IK")
188 call disp%show( rand_D2_IK )
189 call disp%skip()
190
191 call disp%show("call setUnifRand(rand_D2_IK, -3_IK, 2_IK) ! random integer in range [-3 2].")
192 call setUnifRand(rand_D2_IK, -3_IK, 2_IK)
193 call disp%show("rand_D2_IK")
194 call disp%show( rand_D2_IK )
195 call disp%skip()
196
197
198 call disp%skip()
199 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
200 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
201 call disp%show("! Generate `complex`-valued random numbers.")
202 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
203 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
204 call disp%skip()
205
206 call disp%skip()
207 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
208 call disp%show("! Generate a scalar complex random number.")
209 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
210 call disp%skip()
211
212 call disp%show("call setUnifRand(rand_D0_CK) ! random binary complex in the default range [(0,0), (1,1)].")
213 call setUnifRand(rand_D0_CK)
214 call disp%show("rand_D0_CK")
215 call disp%show( rand_D0_CK )
216
217 call disp%show("call setUnifRand(rand_D0_CK, (-3._CK, 3._CK), (2._CK, 5._CK))")
218 call setUnifRand(rand_D0_CK, (-3._CK, 3._CK), (2._CK, 5._CK))
219 call disp%show("rand_D0_CK")
220 call disp%show( rand_D0_CK )
221 call disp%skip()
222
223 call disp%skip()
224 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
225 call disp%show("! Generate a vector of complex random numbers.")
226 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
227 call disp%skip()
228
229 call disp%show("call setUnifRand(rand_D1_CK) ! random binary complex in the default range [(0,0), (1,1)).")
230 call setUnifRand(rand_D1_CK)
231 call disp%show("rand_D1_CK")
232 call disp%show( rand_D1_CK )
233
234 call disp%show("call setUnifRand(rand_D1_CK, (-3._CK, 3._CK), (2._CK, 5._CK)).")
235 call setUnifRand(rand_D1_CK, (-3._CK, 3._CK), (2._CK, 5._CK))
236 call disp%show("rand_D1_CK")
237 call disp%show( rand_D1_CK )
238 call disp%skip()
239
240 call disp%skip()
241 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
242 call disp%show("! Generate a matrix of complex random numbers.")
243 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
244 call disp%skip()
245
246 call disp%show("call setUnifRand(rand_D2_CK) ! random binary complex in the default range [(0,0), (1,1)).")
247 call setUnifRand(rand_D2_CK)
248 call disp%show("rand_D2_CK")
249 call disp%show( rand_D2_CK )
250
251 call disp%show("call setUnifRand(rand_D2_CK, (-3._CK, 3._CK), (2._CK, 5._CK)) ! random complex in range [(-3._CK, 3._CK), (2._CK, -2._CK)).")
252 call setUnifRand(rand_D2_CK, (-3._CK, 3._CK), (2._CK, 5._CK))
253 call disp%show("rand_D2_CK")
254 call disp%show( rand_D2_CK )
255 call disp%skip()
256
257
258 call disp%skip()
259 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
260 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
261 call disp%show("! Generate `real`-valued random numbers.")
262 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
263 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
264 call disp%skip()
265
266 call disp%skip()
267 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
268 call disp%show("! Generate a scalar real random number.")
269 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
270 call disp%skip()
271
272 call disp%show("call setUnifRand(rand_D0_RK) ! random binary real in the default range [0, 1).")
273 call setUnifRand(rand_D0_RK)
274 call disp%show("rand_D0_RK")
275 call disp%show( rand_D0_RK )
276 call disp%skip()
277
278 call disp%show("call setUnifRand(rand_D0_RK, -3._RK, 2._RK) ! random real in range [-3 2).")
279 call setUnifRand(rand_D0_RK, -3._RK, 2._RK)
280 call disp%show("rand_D0_RK")
281 call disp%show( rand_D0_RK )
282 call disp%skip()
283
284 call disp%skip()
285 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
286 call disp%show("! Generate a vector of real random numbers.")
287 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
288 call disp%skip()
289
290 call disp%show("call setUnifRand(rand_D1_RK) ! random binary real in the default range [0, 1).")
291 call setUnifRand(rand_D1_RK)
292 call disp%show("rand_D1_RK")
293 call disp%show( rand_D1_RK )
294 call disp%skip()
295
296 call disp%show("call setUnifRand(rand_D1_RK, -3._RK, 2._RK) ! random real in range [-3 2).")
297 call setUnifRand(rand_D1_RK, -3._RK, 2._RK)
298 call disp%show("rand_D1_RK")
299 call disp%show( rand_D1_RK )
300 call disp%skip()
301
302 call disp%skip()
303 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
304 call disp%show("! Generate a matrix of real random numbers.")
305 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
306 call disp%skip()
307
308 call disp%show("call setUnifRand(rand_D2_RK) ! random binary real in the default range [0, 1).")
309 call setUnifRand(rand_D2_RK)
310 call disp%show("rand_D2_RK")
311 call disp%show( rand_D2_RK )
312 call disp%skip()
313
314 call disp%show("call setUnifRand(rand_D2_RK, -3._RK, 2._RK) ! random real in range [-3 2).")
315 call setUnifRand(rand_D2_RK, -3._RK, 2._RK)
316 call disp%show("rand_D2_RK")
317 call disp%show( rand_D2_RK )
318 call disp%skip()
319
320 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
321 ! Output an example rand array for visualization.
322 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
323
324 block
325 integer :: rand(5000)
326 call setUnifRand(rand, -2, 3)
327 if (0 /= getErrTableWrite(SK_"setUnifRand.IK.txt", rand)) error stop "Table writing failed."
328 end block
329
330 block
331 complex :: rand(5000)
332 call setUnifRand(rand, (-2., +2.), (3., 5.))
333 if (0 /= getErrTableWrite(SK_"setUnifRand.CK.txt", rand)) error stop "Table writing failed."
334 end block
335
336 block
337 real :: rand(5000)
338 call setUnifRand(rand)
339 if (0 /= getErrTableWrite(SK_"setUnifRand.RK.txt", rand)) error stop "Table writing failed."
340 end block
341
342end program example
Generate and return the iostat code resulting from writing the input table of rank 1 or 2 to the spec...
Definition: pm_io.F90:5940
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter RK
The default real kind in the ParaMonte library: real64 in Fortran, c_double in C-Fortran Interoperati...
Definition: pm_kind.F90:543
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
integer, parameter CKS
The single-precision complex kind in Fortran mode. On most platforms, this is a 32-bit real kind.
Definition: pm_kind.F90:570
integer, parameter CK
The default complex kind in the ParaMonte library: real64 in Fortran, c_double_complex in C-Fortran I...
Definition: pm_kind.F90:542
integer, parameter IKS
The single-precision integer kind in Fortran mode. On most platforms, this is a 32-bit integer kind.
Definition: pm_kind.F90:563
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
integer, parameter RKS
The single-precision real kind in Fortran mode. On most platforms, this is an 32-bit real kind.
Definition: pm_kind.F90:567
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4! Generate `logical`-valued random numbers.
5!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7
8
9!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10! Generate a scalar logical random number.
11!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12
13call setUnifRand(rand_D0_LK) ! random binary logical in the default range [.false._LK, .true._LK].
14rand_D0_LK
15F
16
17
18!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19! Generate a vector of logical random numbers.
20!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21
22call setUnifRand(rand_D1_LK) ! random binary logical in the default range [.false._LK, .true._LK].
23rand_D1_LK
24F, F, F, T, F
25
26
27!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28! Generate a matrix of logical random numbers.
29!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30
31call setUnifRand(rand_D2_LK) ! random binary integer in the default range [.false._LK, .true._LK].
32rand_D2_LK
33F, F, T, F, T
34F, F, F, T, T
35T, T, T, T, T
36F, F, T, T, F
37F, F, T, F, F
38
39
40!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42! Generate random `character` values.
43!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45
46
47!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48! Generate a scalar character random value.
49!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50
51call setUnifRand(rand_D0_SK) ! random ASCII character in the default range [char(1), char(127)].
52rand_D0_SK
53"c␄␄␋T"
54
55call setUnifRand(rand_D0_SK, lb = 'AA0aa', ub = 'ZZ9zz') ! random ASCII character in the range ["A", "z"].
56rand_D0_SK
57"TF6bv"
58
59
60!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61! Generate a vector of character random values.
62!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63
64call setUnifRand(rand_D1_SK) ! random ASCII character in the default range [char(1), char(127)].
65rand_D1_SK
66"␆<", "␘V", "n␄", "␖ ", "{
67"
68
69call setUnifRand(rand_D1_SK, lb = 'Aa', ub = 'Zz') ! random ASCII character in the range ["Aa", "Zz"] for each character in string separately.
70rand_D1_SK
71"Ph", "Ld", "Ij", "Bs", "Jr"
72
73
74!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75! Generate a matrix of character random values.
76!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77
78call setUnifRand(rand_D2_SK) ! random ASCII character in the default range [char(1), char(127)].
79rand_D2_SK
80"1␌", "6␑", "
81Z", "␖_", "u
82"
83"S␐", "7/", "]j", "yc", "BS"
84"
85X", "P␟", "Cj", "FB", "I␓"
86"IK", "\ ", "%G", "U~", "rS"
87"/T", "7␌", "i␄", "␜D", "/␂"
88
89call setUnifRand(rand_D2_SK, lb = 'aA', ub = 'zA') ! random ASCII character in the range ["aA", "zZ"] for each character in string separately.
90rand_D2_SK
91"lA", "kA", "nA", "rA", "oA"
92"pA", "iA", "wA", "oA", "iA"
93"oA", "hA", "zA", "nA", "cA"
94"pA", "hA", "sA", "eA", "hA"
95"fA", "yA", "uA", "oA", "sA"
96
97
98!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100! Generate `integer`-valued random numbers.
101!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103
104
105!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106! Generate a scalar integer random number.
107!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108
109call setUnifRand(rand_D0_IK) ! random binary integer in the default range [0, 1].
110rand_D0_IK
111-436855526
112
113call setUnifRand(rand_D0_IK, -3_IK, 2_IK) ! random integer in range [-3 2].
114rand_D0_IK
115-3
116
117
118!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
119! Generate a vector of integer random numbers.
120!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121
122call setUnifRand(rand_D1_IK) ! random binary integer in the default range [0, 1].
123rand_D1_IK
124+221958291, -1524333533, +102453621, -1954123902, -1132113066
125
126call setUnifRand(rand_D1_IK, -3_IK, 2_IK) ! random integer in range [-3 2].
127rand_D1_IK
128+2, +0, -2, +2, -3
129
130
131!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132! Generate a matrix of integer random numbers.
133!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134
135call setUnifRand(rand_D2_IK) ! random binary integer in the default range [0, 1].
136rand_D2_IK
137+1583858167, +1194986061, +311077573, -1731691824, -1367798268
138+1439989713, -1835853355, +236815257, -713556396, +263171253
139-524275296, +450002738, +2070781489, -1724086097, +248529152
140-41538016, +1783075, +945081561, +1848570649, -1446181481
141-1487295929, +437484529, -405113994, -288958080, +1300906661
142
143call setUnifRand(rand_D2_IK, -3_IK, 2_IK) ! random integer in range [-3 2].
144rand_D2_IK
145-2, +2, -3, +0, +0
146+1, +1, -2, +1, +1
147-1, +1, -3, -1, +0
148+2, +0, +0, -2, +2
149-3, +0, +1, -3, +2
150
151
152!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154! Generate `complex`-valued random numbers.
155!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157
158
159!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
160! Generate a scalar complex random number.
161!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
162
163call setUnifRand(rand_D0_CK) ! random binary complex in the default range [(0,0), (1,1)].
164rand_D0_CK
165(+0.417364419, +0.130943596)
166call setUnifRand(rand_D0_CK, (-3._CK, 3._CK), (2._CK, 5._CK))
167rand_D0_CK
168(+1.13813972, +3.93501616)
169
170
171!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172! Generate a vector of complex random numbers.
173!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
174
175call setUnifRand(rand_D1_CK) ! random binary complex in the default range [(0,0), (1,1)).
176rand_D1_CK
177(+0.966455340, +0.607165635), (+0.651334643, +0.131585062), (+0.513167083, +0.388605595), (+0.922375321, +0.867724001), (+0.981042624, +0.821288705)
178call setUnifRand(rand_D1_CK, (-3._CK, 3._CK), (2._CK, 5._CK)).
179rand_D1_CK
180(+1.66721439, +4.30256844), (+0.840822279, +4.23976421), (+0.672178388, +3.48789597), (-0.637461424, +3.56994915), (+0.185032606, +3.04948759)
181
182
183!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184! Generate a matrix of complex random numbers.
185!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
186
187call setUnifRand(rand_D2_CK) ! random binary complex in the default range [(0,0), (1,1)).
188rand_D2_CK
189(+0.218862891E-1, +0.981255889), (+0.745105743E-1, +0.490788877), (+0.146565259, +0.323123932E-1), (+0.548745275, +0.593277097), (+0.405845284, +0.266635120)
190(+0.153346360, +0.673863292), (+0.135374129, +0.890723407), (+0.223126650, +0.993498743), (+0.833109021E-1, +0.701323748), (+0.910903752, +0.402912080)
191(+0.594179749, +0.517330110), (+0.317652524, +0.598502934), (+0.114036083, +0.789304972E-1), (+0.290076733E-1, +0.621506393), (+0.423973739, +0.544738591)
192(+0.212821960, +0.611758113), (+0.468780220, +0.128842533), (+0.464125276, +0.245810330), (+0.950739384, +0.579234958E-1), (+0.192023695, +0.262919486)
193(+0.842358708, +0.450436473), (+0.628429055, +0.316916347), (+0.922125876, +0.121023059), (+0.556875646, +0.564615786), (+0.520692527, +0.596452594)
194call setUnifRand(rand_D2_CK, (-3._CK, 3._CK), (2._CK, 5._CK)) ! random complex in range [(-3._CK, 3._CK), (2._CK, -2._CK)).
195rand_D2_CK
196(+0.738091469E-1, +3.35073853), (-0.878442526E-1, +4.61723137), (+1.24047017, +3.69448948), (+0.690761626, +4.47913551), (+0.311742544, +4.74602556)
197(+0.435556591, +3.20818710), (+0.401053548, +4.93229103), (+0.757468760, +4.78774309), (-1.28237951, +4.46819210), (-0.326411724E-1, +3.78219843)
198(+1.77891588, +3.04638433), (-2.81339359, +4.57104635), (+0.302508593, +3.25695229), (+1.58038449, +3.84150553), (-2.17353439, +3.15319490)
199(-1.99292302, +3.52175331), (-1.24152172, +3.03817749), (+0.895912647E-1, +4.96572924), (+1.89421868, +3.30075359), (+0.144944310, +4.43807364)
200(-2.97971821, +4.93106365), (-0.978890777, +4.20015430), (-1.13656747, +3.01958466), (+0.834674835E-1, +3.34405231), (+1.49977338, +4.85122824)
201
202
203!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
204!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
205! Generate `real`-valued random numbers.
206!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
207!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
208
209
210!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211! Generate a scalar real random number.
212!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213
214call setUnifRand(rand_D0_RK) ! random binary real in the default range [0, 1).
215rand_D0_RK
216+0.858083308
217
218call setUnifRand(rand_D0_RK, -3._RK, 2._RK) ! random real in range [-3 2).
219rand_D0_RK
220+0.410882235E-1
221
222
223!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
224! Generate a vector of real random numbers.
225!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226
227call setUnifRand(rand_D1_RK) ! random binary real in the default range [0, 1).
228rand_D1_RK
229+0.581244826E-1, +0.656493604, +0.464059711, +0.880424142, +0.821333587
230
231call setUnifRand(rand_D1_RK, -3._RK, 2._RK) ! random real in range [-3 2).
232rand_D1_RK
233-0.586777210, +1.44772387, -1.94713724, -1.60709500, +1.27592218
234
235
236!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
237! Generate a matrix of real random numbers.
238!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
239
240call setUnifRand(rand_D2_RK) ! random binary real in the default range [0, 1).
241rand_D2_RK
242+0.137477279, +0.163203001, +0.893971086, +0.438165963, +0.403725505
243+0.739540100, +0.739332914, +0.987030327, +0.299415648, +0.249940991
244+0.591544449, +0.686733723E-1, +0.805284917, +0.434995115, +0.353053570
245+0.325371146, +0.444197059, +0.496734679, +0.226624608, +0.249926209
246+0.247280657, +0.694456637, +0.404434025, +0.736915648, +0.215589464
247
248call setUnifRand(rand_D2_RK, -3._RK, 2._RK) ! random real in range [-3 2).
249rand_D2_RK
250+1.73702133, +1.20116925, -1.78727078, -2.82080030, -1.24754083
251-0.207183838, +1.37277412, -0.375428677, -0.700079083, +0.695659041
252-1.00922668, -1.44973838, -1.37865317, +1.63801718, -0.308179140
253-1.26375926, -0.119983435, -2.68581009, -1.73243535, -2.43803215
254-0.410214543, -1.15624475, -2.95554137, -0.440060735, +0.136399388
255
256

Postprocessing of the example output
1#!/usr/bin/env python
2
3import matplotlib.pyplot as plt
4import pandas as pd
5import numpy as np
6import glob
7import sys
8
9linewidth = 2
10fontsize = 17
11
12marker ={ "CK" : "-"
13 , "IK" : "."
14 , "RK" : "-"
15 }
16xlab = { "CK" : "Uniform Random Value ( real/imaginary components )"
17 , "IK" : "Uniform Random Value ( integer-valued )"
18 , "RK" : "Uniform Random Value ( real-valued )"
19 }
20#legends = [ r"$lb = 0., ub = 1.$"
21# , r"$lb = 0., ub = 1.$"
22# , r"$lb = 0., ub = 1.$"
23# ]
24
25for kind in ["IK", "CK", "RK"]:
26
27 pattern = "*." + kind + ".txt"
28 fileList = glob.glob(pattern)
29 if len(fileList) == 1:
30
31 df = pd.read_csv(fileList[0], delimiter = ",", header = None)
32
33 fig = plt.figure(figsize = 1.25 * np.array([6.4, 4.8]), dpi = 200)
34 ax = plt.subplot()
35
36 for j in range(len(df.values[0,:])):
37 if kind == "CK":
38 plt.hist( df.values[:,j]
39 , histtype = "stepfilled"
40 , alpha = 0.5
41 , bins = 75
42 )
43 else:
44 plt.hist( df.values[:,j]
45 , histtype = "stepfilled"
46 , alpha = 0.5
47 , bins = 75
48 )
49 #ax.legend ( legends
50 # , fontsize = fontsize
51 # )
52 plt.xticks(fontsize = fontsize - 2)
53 plt.yticks(fontsize = fontsize - 2)
54 ax.set_xlabel(xlab[kind], fontsize = 17)
55 ax.set_ylabel("Count", fontsize = 17)
56 ax.set_title("Histograms of {} Uniform random values".format(len(df.values[:, 0])), fontsize = 17)
57
58 plt.grid(visible = True, which = "both", axis = "both", color = "0.85", linestyle = "-")
59 ax.tick_params(axis = "y", which = "minor")
60 ax.tick_params(axis = "x", which = "minor")
61
62 plt.savefig(fileList[0].replace(".txt",".png"))
63
64 elif len(fileList) > 1:
65
66 sys.exit("Ambiguous file list exists.")

Visualization of the example output
Test:
test_pm_distUnif
Bug:

Status: Unresolved
Source: GNU Fortran Compiler gfortran version 10.3
Description: GNU Fortran Compiler gfortran yields an internal compiler error with the expression rand = nint(temp, kind = IKG) in pm_distUnif@routines[IK](@ref pm_kind::IK).inc.F90 file when IKG => integer_kinds(5) on WSL OS.

Remedy (as of ParaMonte Library version 2.0.0): For now, the expression is replaced with rand = int(0.5d0 + temp, kind = IKG).


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Amir Shahmoradi, Oct 16, 2009, 11:14 AM, Michigan

Definition at line 11061 of file pm_distUnif.F90.


The documentation for this interface was generated from the following file: