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

Perform an unbiased random shuffling of the input array, known as the Knuth or Fisher-Yates shuffle. More...

Detailed Description

Perform an unbiased random shuffling of the input array, known as the Knuth or Fisher-Yates shuffle.

Parameters
[in,out]rng: The input/output scalar that can be an object of,
  1. type rngf_type, implying the use of intrinsic Fortran uniform RNG.
  2. type xoshiro256ssw_type, implying the use of xoshiro256** uniform RNG.
(optional, default = rngf_type, implying the use of the intrinsic Fortran URNG.)
[in,out]array: The input/output contiguous array of shape (:) of either
  1. type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU),
  2. type logical of kind any supported by the processor (e.g., LK),
  3. type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64),
  4. type complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128),
  5. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
or,
  1. a scalar assumed-length character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU),
whose first (1:count) elements will be shuffled uniformly-randomly on return.
The rest of the elements of array(count + 1:) will be shuffled but non-uniformly.
[in]count: The input positive scalar integer of default kind IK, containing the number of elements of the unique uniformly-random draws (shuffled elements) from the input array.
If specified, only the first count elements of the input/output sequence array are guaranteed to be randomly uniformly shuffled.
The specified count must not be larger than the length of the input sequence array.
(optional, default = len(array) for scalar character input array, otherwise size(array).)


Possible calling interfaces

call setShuffled(array, count = count)
call setShuffled(rng, array, count = count)
Perform an unbiased random shuffling of the input array, known as the Knuth or Fisher-Yates shuffle.
This module contains procedures and generic interfaces for shuffling arrays of various types.
Warning
The condition 0 <= count must hold for the corresponding input arguments.
The condition count <= lenArray must hold for the corresponding input arguments where lenArray represents the length of the input sequence.
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 become pure in release build mode when the input argument rng is set to an object of type xoshiro256ssw_type.
See also
getChoice
setChoice
getRemapped
setRemapped
getReversed
setReversed


Example usage

1program example
2
3 use pm_kind, only: LK ! All kinds are supported.
4 use pm_kind, only: SK ! All kinds are supported.
5 use pm_kind, only: IK ! All kinds are supported.
6 use pm_kind, only: CK ! All kinds are supported.
7 use pm_kind, only: RK ! All kinds are supported.
8 use pm_io, only: display_type
9 use pm_distUnif, only: getUnifRand
11
12 implicit none
13
14 integer(IK) :: count, itry, ntry = 10
15 type(display_type) :: disp
16 disp = display_type(file = "main.out.F90")
17
18 block
19 character(:), allocatable :: array
20 do itry = 1, ntry
21
22 call disp%skip
23 call disp%show("count = getUnifRand(4, 10)")
24 count = getUnifRand(4, 10)
25 call disp%show("array = getUnifRand(repeat('A', count), repeat('Z', count)) ! generate random array for illustration.")
26 array = getUnifRand(repeat('A', count), repeat('Z', count)) ! generate random array for illustration.
27 call disp%show("array")
28 call disp%show( array, deliml = SK_"""" )
29 call disp%show("call setShuffled(array)")
30 call setShuffled(array)
31 call disp%show("array")
32 call disp%show( array, deliml = SK_"""" )
33
34 call disp%skip
35 call disp%show("count = getUnifRand(0, len(array))")
36 count = getUnifRand(0, len(array))
37 call disp%show("count")
38 call disp%show( count )
39 call disp%show("call setShuffled(array, count) ! draw randomly only `count` elements without replacement.")
40 call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
41 call disp%show("array")
42 call disp%show( array, deliml = SK_"""" )
43
44 end do
45 end block
46
47 block
48 character(2), allocatable :: array(:)
49 do itry = 1, ntry
50
51 call disp%skip
52 call disp%show("count = getUnifRand(4, 10)")
53 count = getUnifRand(4, 10)
54 call disp%show("array = getUnifRand('AA', 'ZZ', count) ! generate random array for illustration.")
55 array = getUnifRand('AA', 'ZZ', count) ! generate random array for illustration.
56 call disp%show("array")
57 call disp%show( array, deliml = SK_"""" )
58 call disp%show("call setShuffled(array)")
59 call setShuffled(array)
60 call disp%show("array")
61 call disp%show( array, deliml = SK_"""" )
62
63 call disp%skip
64 call disp%show("count = getUnifRand(0, size(array))")
65 count = getUnifRand(0, size(array))
66 call disp%show("count")
67 call disp%show( count )
68 call disp%show("call setShuffled(array, count) ! draw randomly only `count` elements without replacement.")
69 call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
70 call disp%show("array")
71 call disp%show( array, deliml = SK_"""" )
72
73 end do
74 end block
75
76 block
77 integer, allocatable :: array(:)
78 do itry = 1, ntry
79
80 call disp%skip
81 call disp%show("count = getUnifRand(4, 10)")
82 count = getUnifRand(4, 10)
83 call disp%show("array = getUnifRand(0, 9, count) ! generate random array for illustration.")
84 array = getUnifRand(0, 9, count) ! generate random array for illustration.
85 call disp%show("array")
86 call disp%show( array )
87 call disp%show("call setShuffled(array)")
88 call setShuffled(array)
89 call disp%show("array")
90 call disp%show( array )
91
92 call disp%skip
93 call disp%show("count = getUnifRand(0, size(array))")
94 count = getUnifRand(0, size(array))
95 call disp%show("count")
96 call disp%show( count )
97 call disp%show("call setShuffled(array, count) ! draw randomly only `count` elements without replacement.")
98 call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
99 call disp%show("array")
100 call disp%show( array )
101
102 end do
103 end block
104
105 block
106 logical, allocatable :: array(:)
107 do itry = 1, ntry
108
109 call disp%skip
110 call disp%show("count = getUnifRand(4, 10)")
111 count = getUnifRand(4, 10)
112 call disp%show("array = getUnifRand(.false., .true., count) ! generate random array for illustration.")
113 array = getUnifRand(.false., .true., count) ! generate random array for illustration.
114 call disp%show("array")
115 call disp%show( array )
116 call disp%show("call setShuffled(array)")
117 call setShuffled(array)
118 call disp%show("array")
119 call disp%show( array )
120
121 call disp%skip
122 call disp%show("count = getUnifRand(0, size(array))")
123 count = getUnifRand(0, size(array))
124 call disp%show("count")
125 call disp%show( count )
126 call disp%show("call setShuffled(array, count) ! draw randomly only `count` elements without replacement.")
127 call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
128 call disp%show("array")
129 call disp%show( array )
130
131 end do
132 end block
133
134 block
135 complex, allocatable :: array(:)
136 do itry = 1, ntry
137
138 call disp%skip
139 call disp%show("count = getUnifRand(4, 10)")
140 count = getUnifRand(4, 10)
141 call disp%show("array = getUnifRand((0., 0.), (1., 1.), count) ! generate random array for illustration.")
142 array = getUnifRand((0., 0.), (1., 1.), count) ! generate random array for illustration.
143 call disp%show("array")
144 call disp%show( array )
145 call disp%show("call setShuffled(array)")
146 call setShuffled(array)
147 call disp%show("array")
148 call disp%show( array )
149
150 call disp%skip
151 call disp%show("count = getUnifRand(0, size(array))")
152 count = getUnifRand(0, size(array))
153 call disp%show("count")
154 call disp%show( count )
155 call disp%show("call setShuffled(array, count) ! draw randomly only `count` elements without replacement.")
156 call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
157 call disp%show("array")
158 call disp%show( array )
159
160 end do
161 end block
162
163 block
164 real, allocatable :: array(:)
165 do itry = 1, ntry
166
167 call disp%skip
168 call disp%show("count = getUnifRand(4, 10)")
169 count = getUnifRand(4, 10)
170 call disp%show("array = getUnifRand(0., 1., count) ! generate random array for illustration.")
171 array = getUnifRand(0., 1., count) ! generate random array for illustration.
172 call disp%show("array")
173 call disp%show( array )
174 call disp%show("call setShuffled(array)")
175 call setShuffled(array)
176 call disp%show("array")
177 call disp%show( array )
178
179 call disp%skip
180 call disp%show("count = getUnifRand(0, size(array))")
181 count = getUnifRand(0, size(array))
182 call disp%show("count")
183 call disp%show( count )
184 call disp%show("call setShuffled(array, count) ! draw randomly only `count` elements without replacement.")
185 call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
186 call disp%show("array")
187 call disp%show( array )
188
189 end do
190 end block
191
192end program example
Generate and return a scalar or a contiguous array of rank 1 of length s1 of randomly uniformly distr...
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 computing various statistical quantities related to t...
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 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 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
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
2count = getUnifRand(4, 10)
3array = getUnifRand(repeat('A', count), repeat('Z', count)) ! generate random array for illustration.
4array
5"NYBHOEWU"
6call setShuffled(array)
7array
8"HBUWYEON"
9
10count = getUnifRand(0, len(array))
11count
12+0
13call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
14array
15"HBUWYEON"
16
17count = getUnifRand(4, 10)
18array = getUnifRand(repeat('A', count), repeat('Z', count)) ! generate random array for illustration.
19array
20"LWIRZEP"
21call setShuffled(array)
22array
23"IPERLWZ"
24
25count = getUnifRand(0, len(array))
26count
27+4
28call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
29array
30"ERLZIWP"
31
32count = getUnifRand(4, 10)
33array = getUnifRand(repeat('A', count), repeat('Z', count)) ! generate random array for illustration.
34array
35"LTZQWWSB"
36call setShuffled(array)
37array
38"ZQWSBLWT"
39
40count = getUnifRand(0, len(array))
41count
42+3
43call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
44array
45"ZWQSBLWT"
46
47count = getUnifRand(4, 10)
48array = getUnifRand(repeat('A', count), repeat('Z', count)) ! generate random array for illustration.
49array
50"YZXDD"
51call setShuffled(array)
52array
53"YDXDZ"
54
55count = getUnifRand(0, len(array))
56count
57+0
58call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
59array
60"YDXDZ"
61
62count = getUnifRand(4, 10)
63array = getUnifRand(repeat('A', count), repeat('Z', count)) ! generate random array for illustration.
64array
65"UWSKWLG"
66call setShuffled(array)
67array
68"LWUSKGW"
69
70count = getUnifRand(0, len(array))
71count
72+6
73call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
74array
75"WLWUKGS"
76
77count = getUnifRand(4, 10)
78array = getUnifRand(repeat('A', count), repeat('Z', count)) ! generate random array for illustration.
79array
80"WLEZ"
81call setShuffled(array)
82array
83"LWZE"
84
85count = getUnifRand(0, len(array))
86count
87+0
88call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
89array
90"LWZE"
91
92count = getUnifRand(4, 10)
93array = getUnifRand(repeat('A', count), repeat('Z', count)) ! generate random array for illustration.
94array
95"UJGDWJG"
96call setShuffled(array)
97array
98"DJGUGJW"
99
100count = getUnifRand(0, len(array))
101count
102+5
103call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
104array
105"UGWDGJJ"
106
107count = getUnifRand(4, 10)
108array = getUnifRand(repeat('A', count), repeat('Z', count)) ! generate random array for illustration.
109array
110"IGSNOO"
111call setShuffled(array)
112array
113"SNGOIO"
114
115count = getUnifRand(0, len(array))
116count
117+2
118call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
119array
120"NGSOIO"
121
122count = getUnifRand(4, 10)
123array = getUnifRand(repeat('A', count), repeat('Z', count)) ! generate random array for illustration.
124array
125"TQKYJSQ"
126call setShuffled(array)
127array
128"QSTKJYQ"
129
130count = getUnifRand(0, len(array))
131count
132+7
133call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
134array
135"YSJQKQT"
136
137count = getUnifRand(4, 10)
138array = getUnifRand(repeat('A', count), repeat('Z', count)) ! generate random array for illustration.
139array
140"BNNEHDTJX"
141call setShuffled(array)
142array
143"BJDEHTNNX"
144
145count = getUnifRand(0, len(array))
146count
147+5
148call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
149array
150"BNDTEHJNX"
151
152count = getUnifRand(4, 10)
153array = getUnifRand('AA', 'ZZ', count) ! generate random array for illustration.
154array
155"ZF", "YL", "HP", "IF", "VW"
156call setShuffled(array)
157array
158"ZF", "HP", "IF", "VW", "YL"
159
160count = getUnifRand(0, size(array))
161count
162+0
163call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
164array
165"ZF", "HP", "IF", "VW", "YL"
166
167count = getUnifRand(4, 10)
168array = getUnifRand('AA', 'ZZ', count) ! generate random array for illustration.
169array
170"UV", "IP", "ND", "FS", "OA", "XC", "QE", "YU", "KX", "OM"
171call setShuffled(array)
172array
173"UV", "KX", "ND", "FS", "YU", "OA", "XC", "QE", "IP", "OM"
174
175count = getUnifRand(0, size(array))
176count
177+3
178call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
179array
180"FS", "ND", "OM", "UV", "YU", "OA", "XC", "QE", "IP", "KX"
181
182count = getUnifRand(4, 10)
183array = getUnifRand('AA', 'ZZ', count) ! generate random array for illustration.
184array
185"DG", "PM", "XR", "WL", "SQ", "TO", "SA"
186call setShuffled(array)
187array
188"TO", "SA", "WL", "PM", "DG", "XR", "SQ"
189
190count = getUnifRand(0, size(array))
191count
192+0
193call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
194array
195"TO", "SA", "WL", "PM", "DG", "XR", "SQ"
196
197count = getUnifRand(4, 10)
198array = getUnifRand('AA', 'ZZ', count) ! generate random array for illustration.
199array
200"AP", "RT", "PN", "LH", "BK", "FZ", "QH", "TW", "SS"
201call setShuffled(array)
202array
203"TW", "BK", "SS", "RT", "AP", "QH", "PN", "FZ", "LH"
204
205count = getUnifRand(0, size(array))
206count
207+6
208call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
209array
210"LH", "RT", "AP", "BK", "TW", "PN", "QH", "FZ", "SS"
211
212count = getUnifRand(4, 10)
213array = getUnifRand('AA', 'ZZ', count) ! generate random array for illustration.
214array
215"RV", "SZ", "ND", "TK", "DW", "XT"
216call setShuffled(array)
217array
218"DW", "RV", "SZ", "XT", "TK", "ND"
219
220count = getUnifRand(0, size(array))
221count
222+5
223call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
224array
225"ND", "RV", "DW", "TK", "XT", "SZ"
226
227count = getUnifRand(4, 10)
228array = getUnifRand('AA', 'ZZ', count) ! generate random array for illustration.
229array
230"TA", "OI", "GF", "JK", "FH", "DB", "DJ", "QT", "TW"
231call setShuffled(array)
232array
233"GF", "OI", "TW", "JK", "FH", "QT", "DJ", "DB", "TA"
234
235count = getUnifRand(0, size(array))
236count
237+9
238call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
239array
240"QT", "DJ", "GF", "FH", "TW", "DB", "OI", "TA", "JK"
241
242count = getUnifRand(4, 10)
243array = getUnifRand('AA', 'ZZ', count) ! generate random array for illustration.
244array
245"VE", "KP", "GI", "TU", "YM"
246call setShuffled(array)
247array
248"VE", "KP", "TU", "GI", "YM"
249
250count = getUnifRand(0, size(array))
251count
252+4
253call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
254array
255"KP", "TU", "YM", "VE", "GI"
256
257count = getUnifRand(4, 10)
258array = getUnifRand('AA', 'ZZ', count) ! generate random array for illustration.
259array
260"NI", "ZM", "BG", "NV", "FH", "IM", "NU"
261call setShuffled(array)
262array
263"FH", "BG", "NV", "ZM", "NI", "IM", "NU"
264
265count = getUnifRand(0, size(array))
266count
267+2
268call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
269array
270"ZM", "NU", "NV", "FH", "NI", "IM", "BG"
271
272count = getUnifRand(4, 10)
273array = getUnifRand('AA', 'ZZ', count) ! generate random array for illustration.
274array
275"JG", "PN", "SH", "YZ", "EH", "UW"
276call setShuffled(array)
277array
278"YZ", "EH", "UW", "SH", "JG", "PN"
279
280count = getUnifRand(0, size(array))
281count
282+1
283call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
284array
285"JG", "EH", "UW", "SH", "YZ", "PN"
286
287count = getUnifRand(4, 10)
288array = getUnifRand('AA', 'ZZ', count) ! generate random array for illustration.
289array
290"SX", "LI", "FZ", "BE", "PM", "MM", "QL", "LQ", "KT", "MD"
291call setShuffled(array)
292array
293"LQ", "LI", "MD", "PM", "FZ", "MM", "QL", "BE", "KT", "SX"
294
295count = getUnifRand(0, size(array))
296count
297+10
298call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
299array
300"MM", "SX", "QL", "PM", "LQ", "KT", "LI", "FZ", "MD", "BE"
301
302count = getUnifRand(4, 10)
303array = getUnifRand(0, 9, count) ! generate random array for illustration.
304array
305+4, +8, +9, +2
306call setShuffled(array)
307array
308+2, +9, +8, +4
309
310count = getUnifRand(0, size(array))
311count
312+3
313call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
314array
315+8, +9, +4, +2
316
317count = getUnifRand(4, 10)
318array = getUnifRand(0, 9, count) ! generate random array for illustration.
319array
320+7, +0, +0, +1, +8, +8, +5, +3, +5
321call setShuffled(array)
322array
323+3, +1, +8, +0, +8, +7, +5, +0, +5
324
325count = getUnifRand(0, size(array))
326count
327+1
328call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
329array
330+0, +1, +8, +0, +8, +7, +5, +3, +5
331
332count = getUnifRand(4, 10)
333array = getUnifRand(0, 9, count) ! generate random array for illustration.
334array
335+3, +7, +6, +9, +1, +1, +3
336call setShuffled(array)
337array
338+1, +6, +7, +3, +9, +3, +1
339
340count = getUnifRand(0, size(array))
341count
342+2
343call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
344array
345+3, +9, +7, +3, +6, +1, +1
346
347count = getUnifRand(4, 10)
348array = getUnifRand(0, 9, count) ! generate random array for illustration.
349array
350+7, +5, +8, +5, +4, +3, +2, +6
351call setShuffled(array)
352array
353+5, +6, +5, +8, +7, +4, +3, +2
354
355count = getUnifRand(0, size(array))
356count
357+7
358call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
359array
360+8, +4, +7, +5, +5, +6, +2, +3
361
362count = getUnifRand(4, 10)
363array = getUnifRand(0, 9, count) ! generate random array for illustration.
364array
365+6, +7, +9, +5
366call setShuffled(array)
367array
368+7, +5, +6, +9
369
370count = getUnifRand(0, size(array))
371count
372+2
373call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
374array
375+6, +9, +7, +5
376
377count = getUnifRand(4, 10)
378array = getUnifRand(0, 9, count) ! generate random array for illustration.
379array
380+5, +3, +7, +5, +9, +4, +3, +5, +6
381call setShuffled(array)
382array
383+3, +9, +7, +3, +6, +4, +5, +5, +5
384
385count = getUnifRand(0, size(array))
386count
387+5
388call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
389array
390+5, +4, +3, +7, +3, +9, +5, +5, +6
391
392count = getUnifRand(4, 10)
393array = getUnifRand(0, 9, count) ! generate random array for illustration.
394array
395+1, +5, +3, +6, +7, +0, +5, +0, +3
396call setShuffled(array)
397array
398+7, +5, +3, +3, +0, +1, +6, +0, +5
399
400count = getUnifRand(0, size(array))
401count
402+5
403call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
404array
405+1, +6, +5, +7, +3, +3, +5, +0, +0
406
407count = getUnifRand(4, 10)
408array = getUnifRand(0, 9, count) ! generate random array for illustration.
409array
410+8, +5, +7, +1, +5, +0, +0
411call setShuffled(array)
412array
413+7, +5, +1, +0, +0, +5, +8
414
415count = getUnifRand(0, size(array))
416count
417+3
418call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
419array
420+5, +0, +7, +0, +5, +1, +8
421
422count = getUnifRand(4, 10)
423array = getUnifRand(0, 9, count) ! generate random array for illustration.
424array
425+2, +8, +2, +8, +0, +7, +5
426call setShuffled(array)
427array
428+7, +8, +0, +2, +8, +2, +5
429
430count = getUnifRand(0, size(array))
431count
432+6
433call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
434array
435+2, +8, +5, +2, +0, +7, +8
436
437count = getUnifRand(4, 10)
438array = getUnifRand(0, 9, count) ! generate random array for illustration.
439array
440+1, +7, +2, +4
441call setShuffled(array)
442array
443+4, +2, +7, +1
444
445count = getUnifRand(0, size(array))
446count
447+3
448call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
449array
450+4, +1, +2, +7
451
452count = getUnifRand(4, 10)
453array = getUnifRand(.false., .true., count) ! generate random array for illustration.
454array
455F, T, T, T, F, F, T, F, F, F
456call setShuffled(array)
457array
458F, F, F, F, T, T, F, T, F, T
459
460count = getUnifRand(0, size(array))
461count
462+9
463call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
464array
465T, F, T, F, F, F, F, T, F, T
466
467count = getUnifRand(4, 10)
468array = getUnifRand(.false., .true., count) ! generate random array for illustration.
469array
470T, T, F, T, T, F, T, T, T, T
471call setShuffled(array)
472array
473T, T, T, T, T, F, T, F, T, T
474
475count = getUnifRand(0, size(array))
476count
477+0
478call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
479array
480T, T, T, T, T, F, T, F, T, T
481
482count = getUnifRand(4, 10)
483array = getUnifRand(.false., .true., count) ! generate random array for illustration.
484array
485T, T, F, T, F, F, F, T, T
486call setShuffled(array)
487array
488F, T, T, T, F, F, F, T, T
489
490count = getUnifRand(0, size(array))
491count
492+7
493call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
494array
495F, T, T, F, T, F, F, T, T
496
497count = getUnifRand(4, 10)
498array = getUnifRand(.false., .true., count) ! generate random array for illustration.
499array
500T, F, F, F, T, T, F
501call setShuffled(array)
502array
503F, T, F, F, T, T, F
504
505count = getUnifRand(0, size(array))
506count
507+7
508call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
509array
510F, T, F, F, T, F, T
511
512count = getUnifRand(4, 10)
513array = getUnifRand(.false., .true., count) ! generate random array for illustration.
514array
515T, F, F, T, T, T
516call setShuffled(array)
517array
518T, T, F, T, T, F
519
520count = getUnifRand(0, size(array))
521count
522+1
523call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
524array
525T, T, F, T, T, F
526
527count = getUnifRand(4, 10)
528array = getUnifRand(.false., .true., count) ! generate random array for illustration.
529array
530F, T, T, F, T
531call setShuffled(array)
532array
533T, F, T, T, F
534
535count = getUnifRand(0, size(array))
536count
537+2
538call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
539array
540T, F, T, T, F
541
542count = getUnifRand(4, 10)
543array = getUnifRand(.false., .true., count) ! generate random array for illustration.
544array
545T, T, F, F
546call setShuffled(array)
547array
548F, F, T, T
549
550count = getUnifRand(0, size(array))
551count
552+0
553call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
554array
555F, F, T, T
556
557count = getUnifRand(4, 10)
558array = getUnifRand(.false., .true., count) ! generate random array for illustration.
559array
560F, F, T, F, F, T, F, F, F, F
561call setShuffled(array)
562array
563T, T, F, F, F, F, F, F, F, F
564
565count = getUnifRand(0, size(array))
566count
567+9
568call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
569array
570F, T, F, F, F, F, T, F, F, F
571
572count = getUnifRand(4, 10)
573array = getUnifRand(.false., .true., count) ! generate random array for illustration.
574array
575F, F, F, F, F
576call setShuffled(array)
577array
578F, F, F, F, F
579
580count = getUnifRand(0, size(array))
581count
582+2
583call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
584array
585F, F, F, F, F
586
587count = getUnifRand(4, 10)
588array = getUnifRand(.false., .true., count) ! generate random array for illustration.
589array
590F, F, F, T, T, F
591call setShuffled(array)
592array
593F, F, F, T, F, T
594
595count = getUnifRand(0, size(array))
596count
597+5
598call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
599array
600F, F, T, F, T, F
601
602count = getUnifRand(4, 10)
603array = getUnifRand((0., 0.), (1., 1.), count) ! generate random array for illustration.
604array
605(+0.307162821, +0.790538311), (+0.322074294E-1, +0.357375324), (+0.936189890, +0.774651766E-1), (+0.764420748, +0.287556648E-1), (+0.891991138, +0.775856435), (+0.347787321, +0.337922215), (+0.787808120, +0.193701982), (+0.443555176, +0.482446969), (+0.748781145, +0.787099719), (+0.849209011, +0.512678385)
606call setShuffled(array)
607array
608(+0.849209011, +0.512678385), (+0.764420748, +0.287556648E-1), (+0.891991138, +0.775856435), (+0.443555176, +0.482446969), (+0.787808120, +0.193701982), (+0.748781145, +0.787099719), (+0.322074294E-1, +0.357375324), (+0.936189890, +0.774651766E-1), (+0.307162821, +0.790538311), (+0.347787321, +0.337922215)
609
610count = getUnifRand(0, size(array))
611count
612+6
613call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
614array
615(+0.307162821, +0.790538311), (+0.748781145, +0.787099719), (+0.347787321, +0.337922215), (+0.322074294E-1, +0.357375324), (+0.891991138, +0.775856435), (+0.443555176, +0.482446969), (+0.764420748, +0.287556648E-1), (+0.936189890, +0.774651766E-1), (+0.849209011, +0.512678385), (+0.787808120, +0.193701982)
616
617count = getUnifRand(4, 10)
618array = getUnifRand((0., 0.), (1., 1.), count) ! generate random array for illustration.
619array
620(+0.627464890, +0.147325516), (+0.745318234, +0.556259394), (+0.325980604, +0.105364203), (+0.495656550, +0.772985816), (+0.986876488, +0.664374471)
621call setShuffled(array)
622array
623(+0.495656550, +0.772985816), (+0.627464890, +0.147325516), (+0.745318234, +0.556259394), (+0.325980604, +0.105364203), (+0.986876488, +0.664374471)
624
625count = getUnifRand(0, size(array))
626count
627+1
628call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
629array
630(+0.325980604, +0.105364203), (+0.627464890, +0.147325516), (+0.745318234, +0.556259394), (+0.495656550, +0.772985816), (+0.986876488, +0.664374471)
631
632count = getUnifRand(4, 10)
633array = getUnifRand((0., 0.), (1., 1.), count) ! generate random array for illustration.
634array
635(+0.501887321, +0.445347488), (+0.185294390, +0.532666564), (+0.391759098, +0.995430171), (+0.608144224, +0.768729210), (+0.174970210, +0.868489087), (+0.341699183, +0.986726820), (+0.582135677, +0.485168338), (+0.157420039E-1, +0.232460499)
636call setShuffled(array)
637array
638(+0.391759098, +0.995430171), (+0.174970210, +0.868489087), (+0.608144224, +0.768729210), (+0.157420039E-1, +0.232460499), (+0.501887321, +0.445347488), (+0.582135677, +0.485168338), (+0.185294390, +0.532666564), (+0.341699183, +0.986726820)
639
640count = getUnifRand(0, size(array))
641count
642+2
643call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
644array
645(+0.157420039E-1, +0.232460499), (+0.501887321, +0.445347488), (+0.608144224, +0.768729210), (+0.391759098, +0.995430171), (+0.174970210, +0.868489087), (+0.582135677, +0.485168338), (+0.185294390, +0.532666564), (+0.341699183, +0.986726820)
646
647count = getUnifRand(4, 10)
648array = getUnifRand((0., 0.), (1., 1.), count) ! generate random array for illustration.
649array
650(+0.161559284, +0.477799237), (+0.263126373, +0.312384069), (+0.582230449, +0.254568577), (+0.320530415, +0.823837101), (+0.174754977, +0.244464040), (+0.876264691, +0.407123148), (+0.118003786, +0.593587697), (+0.731769085, +0.888668954)
651call setShuffled(array)
652array
653(+0.118003786, +0.593587697), (+0.161559284, +0.477799237), (+0.174754977, +0.244464040), (+0.582230449, +0.254568577), (+0.876264691, +0.407123148), (+0.320530415, +0.823837101), (+0.263126373, +0.312384069), (+0.731769085, +0.888668954)
654
655count = getUnifRand(0, size(array))
656count
657+7
658call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
659array
660(+0.263126373, +0.312384069), (+0.582230449, +0.254568577), (+0.118003786, +0.593587697), (+0.731769085, +0.888668954), (+0.320530415, +0.823837101), (+0.174754977, +0.244464040), (+0.876264691, +0.407123148), (+0.161559284, +0.477799237)
661
662count = getUnifRand(4, 10)
663array = getUnifRand((0., 0.), (1., 1.), count) ! generate random array for illustration.
664array
665(+0.350015402, +0.858183622), (+0.990226984, +0.294524431E-2), (+0.817141593, +0.768571973), (+0.878674150, +0.698995590E-2), (+0.590600371, +0.727305412)
666call setShuffled(array)
667array
668(+0.878674150, +0.698995590E-2), (+0.817141593, +0.768571973), (+0.990226984, +0.294524431E-2), (+0.590600371, +0.727305412), (+0.350015402, +0.858183622)
669
670count = getUnifRand(0, size(array))
671count
672+0
673call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
674array
675(+0.878674150, +0.698995590E-2), (+0.817141593, +0.768571973), (+0.990226984, +0.294524431E-2), (+0.590600371, +0.727305412), (+0.350015402, +0.858183622)
676
677count = getUnifRand(4, 10)
678array = getUnifRand((0., 0.), (1., 1.), count) ! generate random array for illustration.
679array
680(+0.729281962, +0.734604120), (+0.963803053, +0.849383473E-1), (+0.174967468, +0.467318892), (+0.824530721E-1, +0.190939844), (+0.637049198, +0.829481900), (+0.378611684E-1, +0.633297861), (+0.778306842, +0.549218297), (+0.306904316, +0.555744469), (+0.813292325, +0.530884922), (+0.121627569, +0.971768796)
681call setShuffled(array)
682array
683(+0.378611684E-1, +0.633297861), (+0.963803053, +0.849383473E-1), (+0.637049198, +0.829481900), (+0.729281962, +0.734604120), (+0.813292325, +0.530884922), (+0.824530721E-1, +0.190939844), (+0.174967468, +0.467318892), (+0.306904316, +0.555744469), (+0.121627569, +0.971768796), (+0.778306842, +0.549218297)
684
685count = getUnifRand(0, size(array))
686count
687+4
688call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
689array
690(+0.306904316, +0.555744469), (+0.637049198, +0.829481900), (+0.174967468, +0.467318892), (+0.778306842, +0.549218297), (+0.813292325, +0.530884922), (+0.824530721E-1, +0.190939844), (+0.963803053, +0.849383473E-1), (+0.378611684E-1, +0.633297861), (+0.121627569, +0.971768796), (+0.729281962, +0.734604120)
691
692count = getUnifRand(4, 10)
693array = getUnifRand((0., 0.), (1., 1.), count) ! generate random array for illustration.
694array
695(+0.515767872, +0.379959583), (+0.975432873, +0.786883175), (+0.509564638, +0.843416035), (+0.989587963, +0.613362432), (+0.943853796, +0.288075447)
696call setShuffled(array)
697array
698(+0.509564638, +0.843416035), (+0.975432873, +0.786883175), (+0.943853796, +0.288075447), (+0.515767872, +0.379959583), (+0.989587963, +0.613362432)
699
700count = getUnifRand(0, size(array))
701count
702+1
703call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
704array
705(+0.989587963, +0.613362432), (+0.975432873, +0.786883175), (+0.943853796, +0.288075447), (+0.515767872, +0.379959583), (+0.509564638, +0.843416035)
706
707count = getUnifRand(4, 10)
708array = getUnifRand((0., 0.), (1., 1.), count) ! generate random array for illustration.
709array
710(+0.565359294, +0.451270163), (+0.167130649, +0.493011653), (+0.759414673, +0.133274555), (+0.932335854, +0.505545616), (+0.274218321, +0.947039723), (+0.322111607, +0.228098810), (+0.120907784, +0.628581464)
711call setShuffled(array)
712array
713(+0.322111607, +0.228098810), (+0.565359294, +0.451270163), (+0.274218321, +0.947039723), (+0.167130649, +0.493011653), (+0.759414673, +0.133274555), (+0.120907784, +0.628581464), (+0.932335854, +0.505545616)
714
715count = getUnifRand(0, size(array))
716count
717+5
718call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
719array
720(+0.932335854, +0.505545616), (+0.565359294, +0.451270163), (+0.759414673, +0.133274555), (+0.167130649, +0.493011653), (+0.322111607, +0.228098810), (+0.120907784, +0.628581464), (+0.274218321, +0.947039723)
721
722count = getUnifRand(4, 10)
723array = getUnifRand((0., 0.), (1., 1.), count) ! generate random array for illustration.
724array
725(+0.989947855, +0.357303500), (+0.879333973, +0.994442046), (+0.782041311, +0.709992528), (+0.985172331, +0.809120238), (+0.938967466E-1, +0.189218283), (+0.712841332, +0.345063508), (+0.407226145, +0.932899892)
726call setShuffled(array)
727array
728(+0.782041311, +0.709992528), (+0.879333973, +0.994442046), (+0.938967466E-1, +0.189218283), (+0.712841332, +0.345063508), (+0.989947855, +0.357303500), (+0.407226145, +0.932899892), (+0.985172331, +0.809120238)
729
730count = getUnifRand(0, size(array))
731count
732+6
733call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
734array
735(+0.879333973, +0.994442046), (+0.989947855, +0.357303500), (+0.782041311, +0.709992528), (+0.712841332, +0.345063508), (+0.938967466E-1, +0.189218283), (+0.407226145, +0.932899892), (+0.985172331, +0.809120238)
736
737count = getUnifRand(4, 10)
738array = getUnifRand((0., 0.), (1., 1.), count) ! generate random array for illustration.
739array
740(+0.513155878, +0.601828098), (+0.971577883, +0.166203797), (+0.969466567, +0.469295621), (+0.271642685, +0.451713920)
741call setShuffled(array)
742array
743(+0.271642685, +0.451713920), (+0.969466567, +0.469295621), (+0.971577883, +0.166203797), (+0.513155878, +0.601828098)
744
745count = getUnifRand(0, size(array))
746count
747+2
748call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
749array
750(+0.971577883, +0.166203797), (+0.513155878, +0.601828098), (+0.271642685, +0.451713920), (+0.969466567, +0.469295621)
751
752count = getUnifRand(4, 10)
753array = getUnifRand(0., 1., count) ! generate random array for illustration.
754array
755+0.202532589, +0.769622028, +0.143602848, +0.421531498
756call setShuffled(array)
757array
758+0.202532589, +0.769622028, +0.421531498, +0.143602848
759
760count = getUnifRand(0, size(array))
761count
762+0
763call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
764array
765+0.202532589, +0.769622028, +0.421531498, +0.143602848
766
767count = getUnifRand(4, 10)
768array = getUnifRand(0., 1., count) ! generate random array for illustration.
769array
770+0.417196572, +0.599771798, +0.119166255, +0.985414326, +0.143546581, +0.600330710, +0.258877039
771call setShuffled(array)
772array
773+0.417196572, +0.985414326, +0.600330710, +0.143546581, +0.599771798, +0.258877039, +0.119166255
774
775count = getUnifRand(0, size(array))
776count
777+6
778call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
779array
780+0.119166255, +0.143546581, +0.985414326, +0.600330710, +0.258877039, +0.417196572, +0.599771798
781
782count = getUnifRand(4, 10)
783array = getUnifRand(0., 1., count) ! generate random array for illustration.
784array
785+0.147778928, +0.280953288, +0.471422076E-1, +0.497323215, +0.359213650
786call setShuffled(array)
787array
788+0.280953288, +0.147778928, +0.497323215, +0.359213650, +0.471422076E-1
789
790count = getUnifRand(0, size(array))
791count
792+3
793call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
794array
795+0.147778928, +0.497323215, +0.280953288, +0.359213650, +0.471422076E-1
796
797count = getUnifRand(4, 10)
798array = getUnifRand(0., 1., count) ! generate random array for illustration.
799array
800+0.686949551, +0.854661107, +0.980191708, +0.864953995, +0.509614825, +0.422438383
801call setShuffled(array)
802array
803+0.686949551, +0.854661107, +0.864953995, +0.422438383, +0.509614825, +0.980191708
804
805count = getUnifRand(0, size(array))
806count
807+3
808call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
809array
810+0.509614825, +0.422438383, +0.864953995, +0.854661107, +0.686949551, +0.980191708
811
812count = getUnifRand(4, 10)
813array = getUnifRand(0., 1., count) ! generate random array for illustration.
814array
815+0.254696548, +0.244022310, +0.493264258, +0.923470855, +0.988085985, +0.213919461, +0.407641470, +0.831542134, +0.785447121, +0.388328433
816call setShuffled(array)
817array
818+0.988085985, +0.923470855, +0.213919461, +0.831542134, +0.407641470, +0.254696548, +0.785447121, +0.244022310, +0.493264258, +0.388328433
819
820count = getUnifRand(0, size(array))
821count
822+8
823call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
824array
825+0.254696548, +0.785447121, +0.407641470, +0.831542134, +0.388328433, +0.244022310, +0.988085985, +0.213919461, +0.493264258, +0.923470855
826
827count = getUnifRand(4, 10)
828array = getUnifRand(0., 1., count) ! generate random array for illustration.
829array
830+0.617913127, +0.869521677, +0.504539192, +0.154397666, +0.686020911, +0.304140031
831call setShuffled(array)
832array
833+0.686020911, +0.869521677, +0.304140031, +0.617913127, +0.504539192, +0.154397666
834
835count = getUnifRand(0, size(array))
836count
837+5
838call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
839array
840+0.504539192, +0.686020911, +0.869521677, +0.154397666, +0.304140031, +0.617913127
841
842count = getUnifRand(4, 10)
843array = getUnifRand(0., 1., count) ! generate random array for illustration.
844array
845+0.740480185, +0.847225189E-1, +0.703719556, +0.503604949, +0.278416932, +0.103355169
846call setShuffled(array)
847array
848+0.103355169, +0.503604949, +0.278416932, +0.847225189E-1, +0.740480185, +0.703719556
849
850count = getUnifRand(0, size(array))
851count
852+3
853call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
854array
855+0.503604949, +0.847225189E-1, +0.703719556, +0.103355169, +0.740480185, +0.278416932
856
857count = getUnifRand(4, 10)
858array = getUnifRand(0., 1., count) ! generate random array for illustration.
859array
860+0.524741113, +0.138318539E-2, +0.587598205, +0.477016389, +0.654073536, +0.730957389E-1, +0.567393243, +0.838758230, +0.461594462
861call setShuffled(array)
862array
863+0.838758230, +0.730957389E-1, +0.654073536, +0.524741113, +0.587598205, +0.461594462, +0.567393243, +0.138318539E-2, +0.477016389
864
865count = getUnifRand(0, size(array))
866count
867+7
868call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
869array
870+0.730957389E-1, +0.587598205, +0.567393243, +0.138318539E-2, +0.838758230, +0.477016389, +0.654073536, +0.524741113, +0.461594462
871
872count = getUnifRand(4, 10)
873array = getUnifRand(0., 1., count) ! generate random array for illustration.
874array
875+0.123144925, +0.665174305, +0.874629080, +0.542289913, +0.243839979, +0.751312315, +0.690864086, +0.194462359
876call setShuffled(array)
877array
878+0.751312315, +0.874629080, +0.690864086, +0.123144925, +0.665174305, +0.243839979, +0.542289913, +0.194462359
879
880count = getUnifRand(0, size(array))
881count
882+4
883call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
884array
885+0.542289913, +0.690864086, +0.194462359, +0.665174305, +0.123144925, +0.243839979, +0.751312315, +0.874629080
886
887count = getUnifRand(4, 10)
888array = getUnifRand(0., 1., count) ! generate random array for illustration.
889array
890+0.430873215, +0.378300905, +0.955829978, +0.962994635, +0.108493626, +0.719010293
891call setShuffled(array)
892array
893+0.962994635, +0.430873215, +0.378300905, +0.955829978, +0.719010293, +0.108493626
894
895count = getUnifRand(0, size(array))
896count
897+1
898call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
899array
900+0.108493626, +0.430873215, +0.378300905, +0.955829978, +0.719010293, +0.962994635
901
Test:
test_pm_arrayShuffle
Todo:
Low Priority: This generic interface can be extended to 2D input objects.
Todo:
High Priority: Update 2021: This task is now resolved.
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 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, September 1, 2017, 12:00 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas at Austin

Definition at line 688 of file pm_arrayShuffle.F90.


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