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

Generate and return a scalar or a contiguous array of rank 1 of length s1 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

Generate and return a scalar or a contiguous array of rank 1 of length s1 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)
[in]lb: The input scalar (or array of the same shape as the desired output rand and other input array-like arguments) of the same type and kind as the output rand, representing the lower bound of the Uniform distribution.
If the output random value rand is to be of type logical, then lb, if present, must be logical(.false., kind = kind(rand)).
If the input argument s1 is present, then lb must be a scalar.
(optional, default = .false.)
[in]ub: The input scalar or array of the same type, kind, rank, and shape as lb, representing the upper bound of the Uniform distribution.
If the input argument s1 is present, ub must be a scalar.
If the output random value rand is to be of type logical, then ub, if present, must be logical(.true., kind = kind(rand)).
(optional, default = .true.)
[in]s1: The input scalar of type integer of default kind IK, representing the size of the output rand array along its first dimension.
(optional. It must be present if s2 is present. If missing, the rank and size of the output rand is that of lb or ub with a non-zero rank.)
[in]s2: The input scalar of type integer of default kind IK, representing the size of the output rand array along its second dimension.
(optional. It must be present if s3 is present. If missing, the rank and size of the output rand is that of lb or ub with a non-zero rank.)
Returns
rand : The output scalar or vector of rank 1 of length s1 or array of the same shape as the non-zero rank of the input lb and ub, containing the uniformly-distributed random output value(s).
If lb and ub are missing, then the output rand is of type logical of default kind LK.
Otherwise, it is either of,
  1. type character of the same kind as lb and ub, of the same length type parameter len as that of lb and ub or,
  2. type integer of the same kind as lb and ub, or
  3. type logical of the same kind as lb and ub, or
  4. type complex of the same kind as lb and ub, or
  5. type real of the same kind as lb and ub.
Note that,
  1. If lb is of type character, then the random characters will be drawn from the character collating sequence of the processor.
  2. If lb and ub are of type integer, then rand will be in the interval [lb, ub].
  3. If lb and ub are of type real, then rand will be in the interval [lb, ub).
  4. If lb and ub are of type character, then rand will be in the interval [lb, ub] as defined by the processor collating sequence.
  5. If lb and ub are of type complex, then rand%re and rand%im will be in the intervals [lb%re, ub%re) and [lb%im, ub%im) respectively.
  6. If lb and ub are both missing, then the output will be a logical of default kind LK with possible values .false._LK and .true._LK.


Possible calling interfaces

rand = getUnifRand() ! Non-elemental, random `logical` output scalar.
rand = getUnifRand(lb, ub) ! Elemental output of the same type and kind as `lb` and `ub`: character, complex, logical, integer, real.
rand(1:s1) = getUnifRand(lb, ub, s1) ! All input arguments must be scalars. Output is a vector of size `s1`, of the same type and kind as `lb` and `ub`.
rand(1:s1,1:s2) = getUnifRand(lb, ub, s1, s2) ! All input arguments must be scalars. Output is a matrix of size `(s1,s2)`, of the same type and kind as `lb` and `ub`.
rand(1:s1,1:s2,1:s3) = getUnifRand(lb, ub, s1, s2, s3) ! All input arguments must be scalars. Output is a cube of size `(s1,s2,s3)`, of the same type and kind as `lb` and `ub`.
rand = getUnifRand(rng) ! Non-elemental, random `logical` output scalar.
rand = getUnifRand(rng, lb, ub) ! Elemental output of the same type and kind as `lb` and `ub`: character, complex, logical, integer, real.
rand(1:s1) = getUnifRand(rng, lb, ub, s1) ! All input arguments must be scalars. Output is a vector of size `s1`, of the same type and kind as `lb` and `ub`.
rand(1:s1,1:s2) = getUnifRand(rng, lb, ub, s1, s2) ! All input arguments must be scalars. Output is a matrix of size `(s1,s2)`, of the same type and kind as `lb` and `ub`.
rand(1:s1,1:s2,1:s3) = getUnifRand(rng, lb, ub, s1, s2, s3) ! All input arguments must be scalars. Output is a cube of size `(s1,s2,s3)`, of the same type and kind as `lb` and `ub`.
!
Generate and return a scalar or a contiguous array of rank 1 of length s1 of randomly uniformly distr...
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 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).
The procedures under the generic interface are all elemental when the input arguments lb and ub are present and s1 is missing.
When the input s1 argument is present, the procedures under this generic interface will be non-elemental, and the input arguments lb and ub must be scalars, because the size of the output rand object is determined by s1.
Additionally, when there is no input argument, the output will always be a scalar logical of default kind LK.
Note
The interface getUnifRand() corresponds to coin-flipping experiment with two possible outputs: .true. (head) and .false. (tail).
See isHead for generating values from a biased-coin flipping experiment.
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 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: getUnifRand
9
10 implicit none
11
12 integer(IK) , parameter :: NP = 5_IK
13
14 character(5,SK) :: rand_D0_SK
15 character(2,SK) :: rand_D1_SK(NP)
16 integer(IK) :: rand_D0_IK, rand_D1_IK(NP)
17 complex(CK) :: rand_D0_CK, rand_D1_CK(NP)
18 real(RK) :: rand_D0_RK, rand_D1_RK(NP)
19
20 type(display_type) :: disp
21
22 disp = display_type(file = "main.out.F90")
23
24
25 call disp%skip()
26 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
27 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
28 call disp%show("! Generate `logical`-valued random numbers.")
29 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
30 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
31 call disp%skip()
32
33 call disp%skip()
34 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
35 call disp%show("! Generate a scalar logical random number.")
36 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
37 call disp%skip()
38
39 call disp%show("getUnifRand() ! single random coin flipping `logical` result in the default range [.false._LK, .true._LK].")
40 call disp%show( getUnifRand() )
41 call disp%skip()
42
43 call disp%skip()
44 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
45 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
46 call disp%show("! Generate random `character` values.")
47 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
48 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
49 call disp%skip()
50
51 call disp%skip()
52 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
53 call disp%show("! Generate a scalar character random value.")
54 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
55 call disp%skip()
56
57 call disp%show("rand_D0_SK = getUnifRand(lb = SK_'AA0aa', ub = SK_'ZZ9zz') ! random ASCII character in the specified range per single character.")
58 rand_D0_SK = getUnifRand(lb = SK_'AA0aa', ub = SK_'ZZ9zz')
59 call disp%show("rand_D0_SK")
60 call disp%show( rand_D0_SK , deliml = SK_"""" )
61 call disp%skip()
62
63 call disp%skip()
64 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
65 call disp%show("! Generate a vector of character random values.")
66 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
67 call disp%skip()
68
69 call disp%show("rand_D1_SK = getUnifRand(lb = SK_'Aa', ub = SK_'Zz', s1 = size(rand_D1_SK, kind = IK)) ! random ASCII character in the range [""Aa"", ""Zz""] per character in string separately.")
70 rand_D1_SK = getUnifRand(lb = SK_'Aa', ub = SK_'Zz', s1 = size(rand_D1_SK, kind = IK))
71 call disp%show("rand_D1_SK")
72 call disp%show( rand_D1_SK , deliml = SK_"""" )
73 call disp%skip()
74
75
76 call disp%skip()
77 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
78 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
79 call disp%show("! Generate `integer`-valued random numbers.")
80 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
81 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
82 call disp%skip()
83
84 call disp%skip()
85 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
86 call disp%show("! Generate a scalar integer random number.")
87 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
88 call disp%skip()
89
90 call disp%show("rand_D0_IK = getUnifRand(-3_IK, 2_IK) ! random integer in range [-3 2].")
91 rand_D0_IK = getUnifRand(-3_IK, 2_IK)
92 call disp%show("rand_D0_IK")
93 call disp%show( rand_D0_IK )
94 call disp%skip()
95
96 call disp%skip()
97 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
98 call disp%show("! Generate a vector of integer random numbers.")
99 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
100 call disp%skip()
101
102 call disp%show("rand_D1_IK = getUnifRand(-3_IK, 2_IK, s1 = size(rand_D1_IK, kind = IK)) ! random integer in range [-3 2].")
103 rand_D1_IK = getUnifRand(-3_IK, 2_IK, s1 = size(rand_D1_IK, kind = IK))
104 call disp%show("rand_D1_IK")
105 call disp%show( rand_D1_IK )
106 call disp%skip()
107
108 call disp%show("getUnifRand([0_IK, 5_IK, 10_IK], 15_IK)")
109 call disp%show( getUnifRand([0_IK, 5_IK, 10_IK], 15_IK) )
110 call disp%skip()
111
112 call disp%show("getUnifRand([0_IK, 6_IK, 11_IK], [5_IK, 10_IK, 15_IK])")
113 call disp%show( getUnifRand([0_IK, 6_IK, 11_IK], [5_IK, 10_IK, 15_IK]) )
114 call disp%skip()
115
116
117 call disp%skip()
118 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
119 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
120 call disp%show("! Generate `complex`-valued random numbers.")
121 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
122 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
123 call disp%skip()
124
125 call disp%skip()
126 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
127 call disp%show("! Generate a scalar complex random number.")
128 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
129 call disp%skip()
130
131 call disp%show("rand_D0_CK = getUnifRand(lb = (-3._CK, -2._CK), ub = (2._CK, 3._CK)).")
132 rand_D0_CK = getUnifRand(lb = (-3._CK, -2._CK), ub = (2._CK, 3._CK))
133 call disp%show("rand_D0_CK")
134 call disp%show( rand_D0_CK )
135 call disp%skip()
136
137 call disp%skip()
138 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
139 call disp%show("! Generate a vector of complex random numbers.")
140 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
141 call disp%skip()
142 call disp%show("rand_D1_CK = getUnifRand((-3._CK, 2._CK), (2._CK, 4._CK), s1 = size(rand_D1_CK, kind = IK)).")
143 rand_D1_CK = getUnifRand((-3._CK, 2._CK), (2._CK, 4._CK), s1 = size(rand_D1_CK, kind = IK))
144 call disp%show("rand_D1_CK")
145 call disp%show( rand_D1_CK )
146 call disp%skip()
147
148
149 call disp%skip()
150 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
151 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
152 call disp%show("! Generate `real`-valued random numbers.")
153 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
154 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
155 call disp%skip()
156
157 call disp%skip()
158 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
159 call disp%show("! Generate a scalar real random number.")
160 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
161 call disp%skip()
162
163 call disp%show("rand_D0_RK = getUnifRand(-3._RK, 2._RK) ! random real in range [-3 2].")
164 rand_D0_RK = getUnifRand(-3._RK, 2._RK)
165 call disp%show("rand_D0_RK")
166 call disp%show( rand_D0_RK )
167 call disp%skip()
168
169 call disp%skip()
170 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
171 call disp%show("! Generate a vector of real random numbers.")
172 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
173 call disp%skip()
174
175 call disp%show("rand_D1_RK = getUnifRand(-3._RK, 2._RK, s1 = size(rand_D1_RK, kind = IK)) ! random real in range [-3 2].")
176 rand_D1_RK = getUnifRand(-3._RK, 2._RK, s1 = size(rand_D1_RK, kind = IK))
177 call disp%show("rand_D1_RK")
178 call disp%show( rand_D1_RK )
179 call disp%skip()
180
181 ! Write an example complex random array to the output file for plotting.
182
183 block
184 integer :: fileUnit,i
185 open(newunit = fileUnit, file = "main.unif.rand.txt")
186 write(fileUnit,"(2(g0,:,','))") getUnifRand((0._CK,100._CK), (100._CK,150._CK), s1 = 500_IK)
187 end block
188
189end program example
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
13getUnifRand() ! single random coin flipping `logical` result in the default range [.false._LK, .true._LK].
14T
15
16
17!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19! Generate random `character` values.
20!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22
23
24!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25! Generate a scalar character random value.
26!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27
28rand_D0_SK = getUnifRand(lb = SK_'AA0aa', ub = SK_'ZZ9zz') ! random ASCII character in the specified range per single character.
29rand_D0_SK
30"DZ9vv"
31
32
33!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34! Generate a vector of character random values.
35!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36
37rand_D1_SK = getUnifRand(lb = SK_'Aa', ub = SK_'Zz', s1 = size(rand_D1_SK, kind = IK)) ! random ASCII character in the range ["Aa", "Zz"] per character in string separately.
38rand_D1_SK
39"Bw", "Py", "Yh", "Mn", "Pq"
40
41
42!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44! Generate `integer`-valued random numbers.
45!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47
48
49!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50! Generate a scalar integer random number.
51!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52
53rand_D0_IK = getUnifRand(-3_IK, 2_IK) ! random integer in range [-3 2].
54rand_D0_IK
55-2
56
57
58!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59! Generate a vector of integer random numbers.
60!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61
62rand_D1_IK = getUnifRand(-3_IK, 2_IK, s1 = size(rand_D1_IK, kind = IK)) ! random integer in range [-3 2].
63rand_D1_IK
64-2, +0, -2, +2, +0
65
66getUnifRand([0_IK, 5_IK, 10_IK], 15_IK)
67+15, +5, +11
68
69getUnifRand([0_IK, 6_IK, 11_IK], [5_IK, 10_IK, 15_IK])
70+2, +8, +11
71
72
73!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75! Generate `complex`-valued random numbers.
76!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78
79
80!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81! Generate a scalar complex random number.
82!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83
84rand_D0_CK = getUnifRand(lb = (-3._CK, -2._CK), ub = (2._CK, 3._CK)).
85rand_D0_CK
86(-0.756565213, +2.16212225)
87
88
89!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90! Generate a vector of complex random numbers.
91!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92
93rand_D1_CK = getUnifRand((-3._CK, 2._CK), (2._CK, 4._CK), s1 = size(rand_D1_CK, kind = IK)).
94rand_D1_CK
95(+0.938228369E-1, +2.58783531), (-1.77636826, +3.08933997), (-2.88835716, +2.37003136), (-0.809475303, +3.26783228), (-1.31865346, +2.82865286)
96
97
98!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100! Generate `real`-valued random numbers.
101!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103
104
105!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106! Generate a scalar real random number.
107!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108
109rand_D0_RK = getUnifRand(-3._RK, 2._RK) ! random real in range [-3 2].
110rand_D0_RK
111-2.40536451
112
113
114!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115! Generate a vector of real random numbers.
116!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117
118rand_D1_RK = getUnifRand(-3._RK, 2._RK, s1 = size(rand_D1_RK, kind = IK)) ! random real in range [-3 2].
119rand_D1_RK
120-0.121795058, +1.16829205, +1.72662830, +0.737801313, +0.159368396
121
122

Postprocessing of the example output
1#!/usr/bin/env python
2
3import matplotlib.pyplot as plt
4import pandas as pd
5import numpy as np
6
7rand = pd.read_csv("main.unif.rand.txt")
8
9fig = plt.figure(figsize = 1.25 * np.array([6.4, 4.8]), dpi = 200)
10ax = plt.subplot()
11
12plt.plot( rand.values[:, 0]
13 , rand.values[:,1]
14 , "."
15 , color = "r"
16 )
17
18ax.set_xlabel("Real Random Component", fontsize = 17)
19ax.set_ylabel("Imaginary Random Component", fontsize = 17)
20ax.set_title("A scatter plot of Complex-valued random numbers".format(len(rand)), fontsize = 17)
21
22plt.grid(visible = True, which = "both", axis = "both", color = "0.85", linestyle = "-")
23ax.tick_params(axis = "y", which = "minor")
24ax.tick_params(axis = "x", which = "minor")
25
26plt.savefig("getUnifRand.CK.png")

Visualization of the example output
Test:
test_pm_distUnif
Todo:
The current random integer generator uses a simple double precision real conversion to integer values.
While this works fairly well for most use cases, it may biased for generating large random integer of kind IK4.
A future remedy should use Bitmask with Rejection as described here.
As of 2021, the use of double precision (64-bit) vs. single-precision for random number generation increases the computational cost of the algorithms by about three times.


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


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