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
15T
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, 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
33F, F, F, T, F
34T, F, T, F, T
35F, T, T, F, F
36T, T, F, F, T
37F, T, F, 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"X(H␎>"
54
55call setUnifRand(rand_D0_SK, lb = 'AA0aa', ub = 'ZZ9zz') ! random ASCII character in the range ["A", "z"].
56rand_D0_SK
57"FT8dq"
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"␛%", "␃d", "{␌", "C@", "kJ"
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"Oy", "Ob", "Uh", "Rq", "Do"
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"
809", "RU", "␗D", "*", "q|"
81":M", "i*", "␚'", "<p", "␜␔"
82"␆/", ";␐", "9m", "}␛", "}}"
83"a␇", "Vi", "_␆", "e7", "␗%"
84"$E", """, "{>", "#@", "g7"
85
86call setUnifRand(rand_D2_SK, lb = 'aA', ub = 'zA') ! random ASCII character in the range ["aA", "zZ"] for each character in string separately.
87rand_D2_SK
88"jA", "yA", "qA", "tA", "jA"
89"zA", "tA", "sA", "hA", "wA"
90"fA", "yA", "yA", "jA", "nA"
91"hA", "sA", "rA", "mA", "nA"
92"tA", "aA", "xA", "fA", "tA"
93
94
95!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97! Generate `integer`-valued random numbers.
98!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100
101
102!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103! Generate a scalar integer random number.
104!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105
106call setUnifRand(rand_D0_IK) ! random binary integer in the default range [0, 1].
107rand_D0_IK
108-1550778044
109
110call setUnifRand(rand_D0_IK, -3_IK, 2_IK) ! random integer in range [-3 2].
111rand_D0_IK
112+2
113
114
115!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116! Generate a vector of integer random numbers.
117!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118
119call setUnifRand(rand_D1_IK) ! random binary integer in the default range [0, 1].
120rand_D1_IK
121+911067877, +580253247, -1909834740, +1335013705, +29763099
122
123call setUnifRand(rand_D1_IK, -3_IK, 2_IK) ! random integer in range [-3 2].
124rand_D1_IK
125-1, +0, -2, -3, +2
126
127
128!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129! Generate a matrix of integer random numbers.
130!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131
132call setUnifRand(rand_D2_IK) ! random binary integer in the default range [0, 1].
133rand_D2_IK
134-1079679412, -59601019, -625958692, -793727220, +1330315409
135+333711401, +572598291, -1965149994, -1999105452, +2116805661
136+166272347, -361791108, +313801283, -1973119100, -1141826094
137-745268411, -1721836505, +1719886329, -997720508, +287898742
138-1122728264, -661545981, -396392651, +2002469396, +1007108166
139
140call setUnifRand(rand_D2_IK, -3_IK, 2_IK) ! random integer in range [-3 2].
141rand_D2_IK
142-1, -1, +1, +2, -3
143-1, -2, -2, -1, +1
144-1, +2, +0, +1, +0
145+1, +0, -1, -3, +2
146-1, +1, +0, -1, -3
147
148
149!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
151! Generate `complex`-valued random numbers.
152!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154
155
156!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157! Generate a scalar complex random number.
158!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159
160call setUnifRand(rand_D0_CK) ! random binary complex in the default range [(0,0), (1,1)].
161rand_D0_CK
162(+0.482312024, +0.422418535)
163call setUnifRand(rand_D0_CK, (-3._CK, 3._CK), (2._CK, 5._CK))
164rand_D0_CK
165(+1.06354070, +4.68714571)
166
167
168!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169! Generate a vector of complex random numbers.
170!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171
172call setUnifRand(rand_D1_CK) ! random binary complex in the default range [(0,0), (1,1)).
173rand_D1_CK
174(+0.994532704E-1, +0.780992627), (+0.591673851, +0.539248407), (+0.656540930, +0.655153513), (+0.264971554, +0.514710903), (+0.282100260, +0.351772010)
175call setUnifRand(rand_D1_CK, (-3._CK, 3._CK), (2._CK, 5._CK)).
176rand_D1_CK
177(-0.298624873, +3.46737146), (-2.94901299, +3.99629068), (+1.71317947, +4.10896778), (+1.71079254, +4.82379103), (-0.115513682, +4.47945404)
178
179
180!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181! Generate a matrix of complex random numbers.
182!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183
184call setUnifRand(rand_D2_CK) ! random binary complex in the default range [(0,0), (1,1)).
185rand_D2_CK
186(+0.512839913, +0.746633172), (+0.378074169, +0.477648318), (+0.597242892, +0.518050671), (+0.970105052, +0.410534203), (+0.628298759, +0.561877191)
187(+0.999160171, +0.299518287), (+0.184468269, +0.735189140), (+0.931638360, +0.969165802), (+0.783276021, +0.398124516), (+0.629791796, +0.602908671)
188(+0.467123568, +0.444758058), (+0.234700561, +0.238329768), (+0.160237074, +0.750348508), (+0.638902307, +0.980197966), (+0.764425397, +0.412401974)
189(+0.599646986, +0.872758090), (+0.501032352, +0.786383331), (+0.383591354, +0.970865905), (+0.190041125, +0.203448772), (+0.515372753, +0.938299775)
190(+0.423564374, +0.342086256), (+0.378184140, +0.850599825), (+0.584431827, +0.821191728), (+0.279428124, +0.604142308), (+0.579030454, +0.798562169)
191call setUnifRand(rand_D2_CK, (-3._CK, 3._CK), (2._CK, 5._CK)) ! random complex in range [(-3._CK, 3._CK), (2._CK, -2._CK)).
192rand_D2_CK
193(-1.73714089, +3.67098761), (-0.799981833, +4.35614395), (-0.192996144, +4.50153542), (+1.98153543, +4.93074465), (+0.891915977, +3.34377766)
194(+0.125078082, +4.55194283), (-1.11124921, +3.92637634), (+1.56113756, +4.51977539), (-1.07489789, +3.50250912), (-0.526072860, +3.07821369)
195(+0.845455050, +4.96920776), (-2.55553198, +4.72601318), (-2.98965693, +4.95120668), (+1.24411798, +3.07769775), (-0.243084550, +4.07232952)
196(+1.75754166, +3.54302168), (+0.374806345, +3.45829582), (+0.470424414, +4.26510286), (-2.71038342, +4.52484512), (-1.84219968, +4.63151312)
197(-0.601720929, +3.51646996), (-2.36046052, +3.08516598), (-1.83439696, +4.13560534), (-0.334648728, +4.94140530), (-1.38124907, +3.90135336)
198
199
200!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202! Generate `real`-valued random numbers.
203!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
204!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
205
206
207!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
208! Generate a scalar real random number.
209!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
210
211call setUnifRand(rand_D0_RK) ! random binary real in the default range [0, 1).
212rand_D0_RK
213+0.654890537
214
215call setUnifRand(rand_D0_RK, -3._RK, 2._RK) ! random real in range [-3 2).
216rand_D0_RK
217-1.75933576
218
219
220!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
221! Generate a vector of real random numbers.
222!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
223
224call setUnifRand(rand_D1_RK) ! random binary real in the default range [0, 1).
225rand_D1_RK
226+0.399635851, +0.890500903, +0.193489313, +0.761683702, +0.535666406
227
228call setUnifRand(rand_D1_RK, -3._RK, 2._RK) ! random real in range [-3 2).
229rand_D1_RK
230-2.54502344, +0.219650269E-1, -0.177106500, +1.93277049, -1.22350585
231
232
233!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234! Generate a matrix of real random numbers.
235!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
236
237call setUnifRand(rand_D2_RK) ! random binary real in the default range [0, 1).
238rand_D2_RK
239+0.284526944, +0.640240133, +0.474784672, +0.108080029, +0.634101927
240+0.956812561, +0.151904881, +0.657458782, +0.794737995, +0.123033524
241+0.559922934, +0.473950386, +0.641952336, +0.173796892, +0.453525722
242+0.963096619E-1, +0.279673040, +0.819945812, +0.335384250, +0.159310997
243+0.491349041, +0.764832199, +0.796371520, +0.461930573, +0.282427609
244
245call setUnifRand(rand_D2_RK, -3._RK, 2._RK) ! random real in range [-3 2).
246rand_D2_RK
247+0.289880157, +1.45865870, -1.83928216, -2.66684890, -2.93343067
248+0.422971666, -1.12360799, +0.558495343, +0.471411169, +1.23507714
249-1.81667531, -0.584695458, +0.744783401, -0.372542262, -0.394539475
250-0.671780229, -2.83652759, +1.78182054, +0.526969850, +1.42886293
251-2.14307761, -2.74374151, -0.475004554, -0.545832753, -2.08736777
252
253

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: