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, T, T, F, T
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
33T, F, F, T, F
34T, F, T, F, F
35F, T, F, T, T
36F, F, F, F, F
37T, F, T, F, T
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"f␎3␟␗"
54
55call setUnifRand(rand_D0_SK, lb = 'AA0aa', ub = 'ZZ9zz') ! random ASCII character in the range ["A", "z"].
56rand_D0_SK
57"GK1sp"
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"$5", "er", "␋r", "&;", "%+"
67
68call setUnifRand(rand_D1_SK, lb = 'Aa', ub = 'Zz') ! random ASCII character in the range ["Aa", "Zz"] for each character in string separately.
69rand_D1_SK
70"Oz", "La", "Rl", "Lk", "Ir"
71
72
73!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74! Generate a matrix of character random values.
75!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76
77call setUnifRand(rand_D2_SK) ! random ASCII character in the default range [char(1), char(127)].
78rand_D2_SK
79"[␛", ".N", "n?", "v␙", "P␏"
80"Mo", "[m", "Hb", "␟Z", "@d"
81""#", " <", "␂1", "I]", "^O"
82"%␟", "%>", "J{", "*/", "dU"
83"LR", "Fs", "␇(", "EO", "Nj"
84
85call setUnifRand(rand_D2_SK, lb = 'aA', ub = 'zA') ! random ASCII character in the range ["aA", "zZ"] for each character in string separately.
86rand_D2_SK
87"lA", "fA", "zA", "aA", "sA"
88"cA", "bA", "fA", "eA", "xA"
89"rA", "vA", "sA", "vA", "lA"
90"eA", "oA", "jA", "cA", "cA"
91"uA", "tA", "tA", "qA", "sA"
92
93
94!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96! Generate `integer`-valued random numbers.
97!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99
100
101!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102! Generate a scalar integer random number.
103!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104
105call setUnifRand(rand_D0_IK) ! random binary integer in the default range [0, 1].
106rand_D0_IK
107-975225947
108
109call setUnifRand(rand_D0_IK, -3_IK, 2_IK) ! random integer in range [-3 2].
110rand_D0_IK
111-3
112
113
114!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115! Generate a vector of integer random numbers.
116!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117
118call setUnifRand(rand_D1_IK) ! random binary integer in the default range [0, 1].
119rand_D1_IK
120+1575142597, -450834387, +669244938, +1853608355, -2127665488
121
122call setUnifRand(rand_D1_IK, -3_IK, 2_IK) ! random integer in range [-3 2].
123rand_D1_IK
124-3, -2, -1, -1, -3
125
126
127!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128! Generate a matrix of integer random numbers.
129!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130
131call setUnifRand(rand_D2_IK) ! random binary integer in the default range [0, 1].
132rand_D2_IK
133-1123179925, +134504671, -1867758580, -56983882, +974885794
134-1613024762, +445423840, -1949618644, +1525795483, +442514079
135-449650362, +1778978784, -659312373, +1955684473, -1575515134
136+2073713180, +1513394460, +457698142, +1542036948, -2072745761
137-307908104, -1921074044, +114511553, +617531569, -1476607733
138
139call setUnifRand(rand_D2_IK, -3_IK, 2_IK) ! random integer in range [-3 2].
140rand_D2_IK
141+1, +1, +0, -2, +0
142-2, -2, -2, -1, +1
143+1, +1, -3, +2, -3
144+2, -1, -2, -2, -1
145+0, -2, +2, +0, +1
146
147
148!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150! Generate `complex`-valued random numbers.
151!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153
154
155!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156! Generate a scalar complex random number.
157!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158
159call setUnifRand(rand_D0_CK) ! random binary complex in the default range [(0,0), (1,1)].
160rand_D0_CK
161(+0.525239944, +0.487838268)
162call setUnifRand(rand_D0_CK, (-3._CK, 3._CK), (2._CK, 5._CK))
163rand_D0_CK
164(-2.66719484, +4.65033865)
165
166
167!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168! Generate a vector of complex random numbers.
169!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
170
171call setUnifRand(rand_D1_CK) ! random binary complex in the default range [(0,0), (1,1)).
172rand_D1_CK
173(+0.417975605, +0.650212288), (+0.109892666, +0.575669169), (+0.257214665, +0.302728891), (+0.132293820, +0.180481911), (+0.635234833, +0.817474425)
174call setUnifRand(rand_D1_CK, (-3._CK, 3._CK), (2._CK, 5._CK)).
175rand_D1_CK
176(+0.880635202, +4.04964113), (+1.87991834, +3.45902157), (-2.96846485, +3.38854694), (+0.241707683, +3.50855303), (-0.140612245, +4.87397814)
177
178
179!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180! Generate a matrix of complex random numbers.
181!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182
183call setUnifRand(rand_D2_CK) ! random binary complex in the default range [(0,0), (1,1)).
184rand_D2_CK
185(+0.154150963, +0.107938647E-1), (+0.861932218, +0.317988515), (+0.351859152, +0.664392531), (+0.201444089, +0.760473847), (+0.874049723, +0.797904849)
186(+0.214663863, +0.330731273), (+0.848656535, +0.850351453E-1), (+0.974084020, +0.587461710), (+0.517491519, +0.870555103), (+0.374649704, +0.686064482)
187(+0.546197057, +0.815288424), (+0.338277638, +0.748024404), (+0.189188421, +0.319404662), (+0.322303355, +0.488472581), (+0.602265537, +0.166299343)
188(+0.425267875, +0.163139164), (+0.893530726, +0.215405345), (+0.941966295, +0.673673749E-1), (+0.271834671, +0.140795350), (+0.914202988, +0.298280776)
189(+0.701750755, +0.879466772), (+0.322951555, +0.598841310), (+0.957303822, +0.759807885), (+0.173094034, +0.331221759), (+0.422631264, +0.167849779)
190call setUnifRand(rand_D2_CK, (-3._CK, 3._CK), (2._CK, 5._CK)) ! random complex in range [(-3._CK, 3._CK), (2._CK, -2._CK)).
191rand_D2_CK
192(+0.758638203, +3.14990425), (+1.70777416, +3.51842117), (-1.59673572, +4.36834049), (+0.435485363, +3.68693161), (+1.09732914, +3.92425156)
193(-0.521290421, +3.49146652), (-1.29365528, +3.78830242), (-2.99138498, +4.56841469), (-0.826814055, +4.79005098), (+1.84468436, +4.73858643)
194(-1.38406634, +3.91339493), (-0.412080765, +3.55408049), (-0.596547961, +4.63165188), (-1.72978294, +3.69970989), (+0.858932853, +3.70932508)
195(+1.11270440, +3.59204197), (-0.522781253, +3.99607372), (+0.463968635, +4.98884058), (+1.30223048, +3.87210655), (-1.64944053, +3.07271051)
196(-1.07222545, +3.90343952), (-0.516059518, +4.18118382), (-1.61826015, +3.14822578), (-0.509538293, +3.34560013), (+1.73236501, +3.32070923)
197
198
199!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
200!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201! Generate `real`-valued random numbers.
202!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
204
205
206!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
207! Generate a scalar real random number.
208!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209
210call setUnifRand(rand_D0_RK) ! random binary real in the default range [0, 1).
211rand_D0_RK
212+0.547004938
213
214call setUnifRand(rand_D0_RK, -3._RK, 2._RK) ! random real in range [-3 2).
215rand_D0_RK
216-1.68930984
217
218
219!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
220! Generate a vector of real random numbers.
221!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
222
223call setUnifRand(rand_D1_RK) ! random binary real in the default range [0, 1).
224rand_D1_RK
225+0.590782762E-1, +0.879262149, +0.390571356E-2, +0.777250469, +0.568826616
226
227call setUnifRand(rand_D1_RK, -3._RK, 2._RK) ! random real in range [-3 2).
228rand_D1_RK
229+0.819801807, -0.289891243, -2.38394451, +1.48984289, +1.00179565
230
231
232!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
233! Generate a matrix of real random numbers.
234!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
235
236call setUnifRand(rand_D2_RK) ! random binary real in the default range [0, 1).
237rand_D2_RK
238+0.962382555, +0.815497279, +0.789634526, +0.547535002, +0.224926770
239+0.386942625E-1, +0.229563117, +0.610890031, +0.565110683, +0.562517107
240+0.185824037, +0.821961224, +0.691421330, +0.287817121, +0.139091969
241+0.902643383, +0.830449283, +0.316975594, +0.848599255, +0.379116118
242+0.290326834, +0.898208857, +0.977422595, +0.127535641, +0.513128161
243
244call setUnifRand(rand_D2_RK, -3._RK, 2._RK) ! random real in range [-3 2).
245rand_D2_RK
246-1.64051270, +1.58160996, -1.10747266, +1.17239428, -1.70654142
247-0.688870788, -0.656294942, -2.11774945, +0.634704649, +0.576334417
248+1.65606952, -0.390764952, -1.86045301, +1.37227905, +0.856558084E-1
249-2.27072096, -0.850019574, -2.06927657, -2.51169848, -0.788066506
250+0.255499244, -1.27872634, -0.755657792, +0.827765584, -0.116707563
251
252

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).
Bug:

Status: Unresolved
Source: Intel LLVM Fortran Compiler ifx version 2025.0.0 20241008
Description: Intel LLVM Fortran Compiler ifx version 2025.0.0 20241008 cannot compile the following two lines of code in the include file pm_distUnif@routines.inc.F90.
call setUnifRand(RNG rand%re, lb%re, ub%re)
call setUnifRand(RNG rand%im, lb%im, ub%im)

Note that ifort can readily compile the above lines of code.
Uncomment the above two lines to regenerate the compile-time error.

Remedy (as of ParaMonte Library version 2.0.0): For now, these two lines are commented out for Intel compilers and replaced with the following.

call setUnifRand(RNG rand%re, real(lb, CKG), real(ub, CKG))
call setUnifRand(RNG rand%im, aimag(lb), aimag(ub))


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 11083 of file pm_distUnif.F90.


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