Perform an unbiased random shuffling of the input array, known as the Knuth or Fisher-Yates shuffle, and generate and return the new reshuffled array.
- Parameters
-
[in] | array | : The input contiguous array of shape (:) of either
-
type
character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU),
-
type
logical of kind any supported by the processor (e.g., LK),
-
type
integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64),
-
type
complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128),
-
type
real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
-
type css_pdt,
-
type css_type,
or,
-
a scalar assumed-length
character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU),
whose elements will be shuffled uniformly-randomly in the output arrayShuffled on return.
|
[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 .
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) .) |
- Returns
arrayShuffled
: The output allocatable
object of the same type, kind, rank, and shape as the input array
of size (1:count)
whose elements are set from the randomly-shuffled elements of array
.
Possible calling interfaces ⛓
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
.
- See also
- getChoice
setChoice
setShuffled
getRemapped
setRemapped
getReversed
setReversed
Example usage ⛓
15 integer(IK) :: count, itry, ntry
= 10
16 type(display_type) :: disp
20 character(:),
allocatable :: array
24 call disp%show(
"count = getUnifRand(4, 10)")
26 call disp%show(
"array = getUnifRand(repeat('A', count), repeat('Z', count)) ! generate random array for illustration.")
27 array
= getUnifRand(
repeat(
'A', count),
repeat(
'Z', count))
29 call disp%show( array, deliml
= SK_
"""" )
30 call disp%show(
"array = getShuffled(array)")
33 call disp%show( array, deliml
= SK_
"""" )
34 call disp%show(
"count = getUnifRand(0, len(array))")
38 call disp%show(
"array = getShuffled(array, count) ! draw randomly only `count` elements without replacement.")
41 call disp%show( array, deliml
= SK_
"""" )
47 character(
2),
allocatable :: array(:)
51 call disp%show(
"count = getUnifRand(4, 10)")
53 call disp%show(
"array = getUnifRand('AA', 'ZZ', count) ! generate random array for illustration.")
56 call disp%show( array, deliml
= SK_
"""" )
57 call disp%show(
"array = getShuffled(array)")
60 call disp%show( array, deliml
= SK_
"""" )
61 call disp%show(
"count = getUnifRand(0, size(array))")
65 call disp%show(
"array = getShuffled(array, count) ! draw randomly only `count` elements without replacement.")
68 call disp%show( array, deliml
= SK_
"""" )
74 integer,
allocatable :: array(:)
78 call disp%show(
"count = getUnifRand(4, 10)")
80 call disp%show(
"array = getUnifRand(0, 9, count) ! generate random array for illustration.")
84 call disp%show(
"array = getShuffled(array)")
88 call disp%show(
"count = getUnifRand(0, size(array))")
92 call disp%show(
"array = getShuffled(array, count) ! draw randomly only `count` elements without replacement.")
101 logical,
allocatable :: array(:)
105 call disp%show(
"count = getUnifRand(4, 10)")
107 call disp%show(
"array = getUnifRand(.false., .true., count) ! generate random array for illustration.")
111 call disp%show(
"array = getShuffled(array)")
115 call disp%show(
"count = getUnifRand(0, size(array))")
119 call disp%show(
"array = getShuffled(array, count) ! draw randomly only `count` elements without replacement.")
128 complex,
allocatable :: array(:)
132 call disp%show(
"count = getUnifRand(4, 10)")
134 call disp%show(
"array = getUnifRand((0., 0.), (1., 1.), count) ! generate random array for illustration.")
138 call disp%show(
"array = getShuffled(array)")
142 call disp%show(
"count = getUnifRand(0, size(array))")
146 call disp%show(
"array = getShuffled(array, count) ! draw randomly only `count` elements without replacement.")
155 real,
allocatable :: array(:)
159 call disp%show(
"count = getUnifRand(4, 10)")
161 call disp%show(
"array = getUnifRand(0., 1., count) ! generate random array for illustration.")
165 call disp%show(
"array = getShuffled(array)")
169 call disp%show(
"count = getUnifRand(0, size(array))")
173 call disp%show(
"array = getShuffled(array, count) ! draw randomly only `count` elements without replacement.")
Generate minimally-spaced character, integer, real sequences or sequences at fixed intervals of size ...
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.
This is a generic method of the derived type display_type with pass attribute.
This module contains procedures and generic interfaces for generating ranges of discrete character,...
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...
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
integer, parameter RK
The default real kind in the ParaMonte library: real64 in Fortran, c_double in C-Fortran Interoperati...
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
integer, parameter CK
The default complex kind in the ParaMonte library: real64 in Fortran, c_double_complex in C-Fortran I...
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Generate and return an object of type display_type.
Example Unix compile command via Intel ifort
compiler ⛓
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example Windows Batch compile command via Intel ifort
compiler ⛓
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
Example Unix / MinGW compile command via GNU gfortran
compiler ⛓
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example output ⛓
3array
= getUnifRand(
repeat(
'A', count),
repeat(
'Z', count))
17array
= getUnifRand(
repeat(
'A', count),
repeat(
'Z', count))
31array
= getUnifRand(
repeat(
'A', count),
repeat(
'Z', count))
45array
= getUnifRand(
repeat(
'A', count),
repeat(
'Z', count))
59array
= getUnifRand(
repeat(
'A', count),
repeat(
'Z', count))
73array
= getUnifRand(
repeat(
'A', count),
repeat(
'Z', count))
87array
= getUnifRand(
repeat(
'A', count),
repeat(
'Z', count))
101array
= getUnifRand(
repeat(
'A', count),
repeat(
'Z', count))
115array
= getUnifRand(
repeat(
'A', count),
repeat(
'Z', count))
129array
= getUnifRand(
repeat(
'A', count),
repeat(
'Z', count))
145"YE",
"GZ",
"YM",
"LE",
"NR",
"NA",
"FN",
"HO",
"JY"
148"GZ",
"YM",
"JY",
"NA",
"FN",
"YE",
"HO",
"NR",
"LE"
159"HI",
"LB",
"NF",
"NQ",
"KG",
"KK"
162"KK",
"HI",
"NQ",
"NF",
"KG",
"LB"
173"PU",
"NR",
"VY",
"PR",
"TE",
"SH",
"DY"
176"NR",
"DY",
"TE",
"VY",
"PR",
"PU",
"SH"
182"DY",
"PU",
"SH",
"VY",
"PR",
"NR"
187"LJ",
"RP",
"CJ",
"ME",
"KW",
"TK",
"RY"
190"KW",
"RY",
"LJ",
"RP",
"ME",
"CJ",
"TK"
201"TV",
"HP",
"CL",
"MZ"
204"HP",
"CL",
"TV",
"MZ"
215"AO",
"ZZ",
"RY",
"YU",
"WW",
"JF"
218"YU",
"JF",
"WW",
"ZZ",
"RY",
"AO"
224"AO",
"WW",
"JF",
"ZZ",
"YU"
229"AD",
"BB",
"DF",
"HO",
"WL"
232"BB",
"AD",
"DF",
"WL",
"HO"
243"EB",
"OK",
"PV",
"SJ",
"DS",
"YT",
"CV",
"QV",
"IC"
246"PV",
"YT",
"EB",
"DS",
"QV",
"IC",
"SJ",
"CV",
"OK"
252"QV",
"EB",
"CV",
"YT",
"SJ",
"DS"
257"SK",
"GN",
"AX",
"AV",
"IC",
"VO",
"IX"
260"SK",
"AX",
"AV",
"IX",
"VO",
"IC",
"GN"
271"ND",
"LM",
"BA",
"ZA"
274"BA",
"ND",
"LM",
"ZA"
285+6,
+5,
+0,
+5,
+6,
+3,
+8,
+7
288+3,
+8,
+7,
+6,
+5,
+6,
+5,
+0
327+1,
+1,
+2,
+0,
+8,
+8,
+4,
+8,
+6
330+2,
+1,
+0,
+8,
+6,
+8,
+4,
+8,
+1
336+2,
+1,
+8,
+8,
+8,
+4
341+0,
+7,
+8,
+7,
+7,
+2,
+1,
+2,
+0
344+2,
+7,
+0,
+7,
+7,
+1,
+0,
+8,
+2
350+7,
+0,
+7,
+1,
+2,
+2,
+7
355+7,
+6,
+8,
+7,
+3,
+5,
+0,
+2
358+3,
+7,
+6,
+2,
+0,
+8,
+7,
+5
369+9,
+3,
+3,
+1,
+3,
+2,
+7
372+3,
+1,
+3,
+3,
+2,
+9,
+7
383+7,
+1,
+2,
+0,
+1,
+5
386+5,
+0,
+7,
+2,
+1,
+1
411+6,
+4,
+7,
+9,
+1,
+2
414+7,
+1,
+2,
+4,
+6,
+9
439T, T, T, F, F, T, F, T, F
442F, T, T, F, F, T, F, T, T
453T, F, T, F, T, T, F, F, F
456F, T, T, F, T, F, F, F, T
467F, T, F, F, F, F, F, T
470F, T, F, F, F, F, F, T
509F, F, F, T, T, F, T, F
512F, F, F, T, F, T, T, F
518F, F, F, F, T, T, T, F
523T, T, T, T, T, F, F, T
526F, T, T, T, T, T, F, T
551F, T, F, T, F, T, T, F
554T, F, T, F, T, F, T, F
565(
+0.236457169,
+0.372481942E-1), (
+0.620558321,
+0.225238979), (
+0.613987088,
+0.198738396), (
+0.450425982,
+0.975796163), (
+0.588115931,
+0.703201532)
568(
+0.613987088,
+0.198738396), (
+0.450425982,
+0.975796163), (
+0.236457169,
+0.372481942E-1), (
+0.620558321,
+0.225238979), (
+0.588115931,
+0.703201532)
574(
+0.450425982,
+0.975796163), (
+0.588115931,
+0.703201532), (
+0.613987088,
+0.198738396)
579(
+0.192514718,
+0.113111556), (
+0.437338352,
+0.722880661), (
+0.547305286,
+0.122749269), (
+0.969577551,
+0.986249208), (
+0.712779939,
+0.147970319), (
+0.750182509,
+0.254819512), (
+0.321369529,
+0.914896727), (
+0.837500691E-1,
+0.520659506)
582(
+0.750182509,
+0.254819512), (
+0.547305286,
+0.122749269), (
+0.321369529,
+0.914896727), (
+0.437338352,
+0.722880661), (
+0.837500691E-1,
+0.520659506), (
+0.712779939,
+0.147970319), (
+0.969577551,
+0.986249208), (
+0.192514718,
+0.113111556)
588(
+0.437338352,
+0.722880661), (
+0.192514718,
+0.113111556), (
+0.712779939,
+0.147970319), (
+0.321369529,
+0.914896727)
593(
+0.446414232,
+0.161339223), (
+0.773889959,
+0.736664712), (
+0.458979607,
+0.163619936), (
+0.649872243,
+0.726339519), (
+0.822546601,
+0.733868659), (
+0.875087023,
+0.970146537), (
+0.842108309,
+0.837211013), (
+0.252065718,
+0.943914294)
596(
+0.842108309,
+0.837211013), (
+0.773889959,
+0.736664712), (
+0.822546601,
+0.733868659), (
+0.875087023,
+0.970146537), (
+0.252065718,
+0.943914294), (
+0.446414232,
+0.161339223), (
+0.649872243,
+0.726339519), (
+0.458979607,
+0.163619936)
602(
+0.446414232,
+0.161339223), (
+0.458979607,
+0.163619936), (
+0.773889959,
+0.736664712), (
+0.649872243,
+0.726339519)
607(
+0.886526108E-1,
+0.417054236), (
+0.873563528,
+0.526678562E-2), (
+0.227147043,
+0.982010782), (
+0.668107748,
+0.789273798), (
+0.534331262,
+0.736161888), (
+0.442174315,
+0.648055017), (
+0.402749002,
+0.521283090), (
+0.428591073,
+0.751927495)
610(
+0.886526108E-1,
+0.417054236), (
+0.227147043,
+0.982010782), (
+0.668107748,
+0.789273798), (
+0.534331262,
+0.736161888), (
+0.402749002,
+0.521283090), (
+0.873563528,
+0.526678562E-2), (
+0.442174315,
+0.648055017), (
+0.428591073,
+0.751927495)
616(
+0.873563528,
+0.526678562E-2), (
+0.442174315,
+0.648055017), (
+0.534331262,
+0.736161888), (
+0.402749002,
+0.521283090), (
+0.886526108E-1,
+0.417054236), (
+0.428591073,
+0.751927495), (
+0.668107748,
+0.789273798)
621(
+0.467798114E-1,
+0.495126069), (
+0.855228126,
+0.681790411), (
+0.618081629,
+0.105156839), (
+0.905384421E-1,
+0.194232464), (
+0.252223015E-1,
+0.618544102), (
+0.887766719,
+0.926808834), (
+0.144039154,
+0.613445282), (
+0.381111920,
+0.953515172)
624(
+0.618081629,
+0.105156839), (
+0.252223015E-1,
+0.618544102), (
+0.905384421E-1,
+0.194232464), (
+0.381111920,
+0.953515172), (
+0.144039154,
+0.613445282), (
+0.855228126,
+0.681790411), (
+0.887766719,
+0.926808834), (
+0.467798114E-1,
+0.495126069)
630(
+0.618081629,
+0.105156839), (
+0.905384421E-1,
+0.194232464), (
+0.887766719,
+0.926808834), (
+0.467798114E-1,
+0.495126069), (
+0.144039154,
+0.613445282)
635(
+0.923682928,
+0.587326944), (
+0.303708136,
+0.677110076), (
+0.712238550E-1,
+0.487036228), (
+0.675812304,
+0.872579634), (
+0.719198704,
+0.816288471)
638(
+0.719198704,
+0.816288471), (
+0.303708136,
+0.677110076), (
+0.712238550E-1,
+0.487036228), (
+0.675812304,
+0.872579634), (
+0.923682928,
+0.587326944)
644(
+0.712238550E-1,
+0.487036228)
649(
+0.473743439,
+0.971214175), (
+0.515890002,
+0.486422122), (
+0.736594200E-1,
+0.172737062), (
+0.836741865,
+0.294061899E-1), (
+0.199129045,
+0.705178976), (
+0.642369270,
+0.686233044E-1), (
+0.565157533,
+0.707833767), (
+0.688023686,
+0.534220278), (
+0.606411636,
+0.543363988), (
+0.428259373E-1,
+0.214541256)
652(
+0.428259373E-1,
+0.214541256), (
+0.688023686,
+0.534220278), (
+0.642369270,
+0.686233044E-1), (
+0.736594200E-1,
+0.172737062), (
+0.606411636,
+0.543363988), (
+0.836741865,
+0.294061899E-1), (
+0.473743439,
+0.971214175), (
+0.565157533,
+0.707833767), (
+0.515890002,
+0.486422122), (
+0.199129045,
+0.705178976)
658(
+0.515890002,
+0.486422122), (
+0.736594200E-1,
+0.172737062), (
+0.836741865,
+0.294061899E-1), (
+0.565157533,
+0.707833767), (
+0.642369270,
+0.686233044E-1), (
+0.606411636,
+0.543363988), (
+0.688023686,
+0.534220278)
663(
+0.294996440,
+0.270303965), (
+0.759801030,
+0.482282102), (
+0.237049341,
+0.539956331), (
+0.506844223,
+0.638170362), (
+0.294561207,
+0.570023656E-1), (
+0.440932751,
+0.773765802), (
+0.163222790,
+0.947291255E-1)
666(
+0.759801030,
+0.482282102), (
+0.506844223,
+0.638170362), (
+0.294996440,
+0.270303965), (
+0.294561207,
+0.570023656E-1), (
+0.237049341,
+0.539956331), (
+0.163222790,
+0.947291255E-1), (
+0.440932751,
+0.773765802)
672(
+0.294561207,
+0.570023656E-1), (
+0.759801030,
+0.482282102), (
+0.163222790,
+0.947291255E-1)
677(
+0.557914972E-1,
+0.826946855), (
+0.183230162,
+0.851827085), (
+0.536072254E-2,
+0.653061867E-1), (
+0.144756615,
+0.921711981), (
+0.861820281,
+0.206179500), (
+0.924912632,
+0.768901348), (
+0.401797593,
+0.590510428), (
+0.663143396E-1,
+0.531136811), (
+0.438815534,
+0.442660034)
680(
+0.861820281,
+0.206179500), (
+0.557914972E-1,
+0.826946855), (
+0.924912632,
+0.768901348), (
+0.401797593,
+0.590510428), (
+0.144756615,
+0.921711981), (
+0.663143396E-1,
+0.531136811), (
+0.536072254E-2,
+0.653061867E-1), (
+0.438815534,
+0.442660034), (
+0.183230162,
+0.851827085)
686(
+0.144756615,
+0.921711981)
691(
+0.651332021,
+0.758505583), (
+0.888592005E-2,
+0.393595159), (
+0.420730114,
+0.904795408), (
+0.973716795,
+0.193711460), (
+0.993791223E-1,
+0.169614196), (
+0.632548213,
+0.379353344), (
+0.946054697,
+0.707690001), (
+0.690547824,
+0.830768168), (
+0.387958944,
+0.831639171), (
+0.348164678,
+0.327145576)
694(
+0.973716795,
+0.193711460), (
+0.888592005E-2,
+0.393595159), (
+0.420730114,
+0.904795408), (
+0.348164678,
+0.327145576), (
+0.632548213,
+0.379353344), (
+0.993791223E-1,
+0.169614196), (
+0.651332021,
+0.758505583), (
+0.387958944,
+0.831639171), (
+0.690547824,
+0.830768168), (
+0.946054697,
+0.707690001)
700(
+0.690547824,
+0.830768168)
705+0.832107842,
+0.450377226,
+0.233305693,
+0.919365764,
+0.698654234,
+0.178015947,
+0.446732998,
+0.583591759,
+0.431384206,
+0.756679416
708+0.431384206,
+0.233305693,
+0.446732998,
+0.178015947,
+0.698654234,
+0.756679416,
+0.832107842,
+0.583591759,
+0.450377226,
+0.919365764
714+0.698654234,
+0.832107842,
+0.756679416
719+0.254659474,
+0.988009214,
+0.199089527,
+0.236618996,
+0.416619837,
+0.424170792
722+0.424170792,
+0.199089527,
+0.236618996,
+0.254659474,
+0.416619837,
+0.988009214
728+0.416619837,
+0.236618996,
+0.988009214
733+0.311739385,
+0.838033676,
+0.617473900,
+0.760530472,
+0.985780478,
+0.944927096,
+0.666189075
736+0.838033676,
+0.617473900,
+0.944927096,
+0.760530472,
+0.985780478,
+0.666189075,
+0.311739385
742+0.760530472,
+0.666189075,
+0.617473900,
+0.985780478,
+0.838033676
747+0.934136748,
+0.532863557,
+0.801217854,
+0.347375393,
+0.984584630,
+0.548526406,
+0.834214330
750+0.984584630,
+0.548526406,
+0.801217854,
+0.934136748,
+0.532863557,
+0.834214330,
+0.347375393
761+0.662213027,
+0.591104627E-1,
+0.463947833,
+0.664843857,
+0.917766273,
+0.499189675,
+0.693770647E-1,
+0.701038361,
+0.606510937,
+0.306886435E-1
764+0.499189675,
+0.664843857,
+0.701038361,
+0.591104627E-1,
+0.306886435E-1,
+0.693770647E-1,
+0.606510937,
+0.917766273,
+0.463947833,
+0.662213027
770+0.701038361,
+0.662213027,
+0.693770647E-1
775+0.402232409,
+0.113128424,
+0.982472301E-1,
+0.414122880,
+0.144274533,
+0.527621746,
+0.978948355,
+0.765560031,
+0.121542394
778+0.113128424,
+0.765560031,
+0.527621746,
+0.144274533,
+0.402232409,
+0.121542394,
+0.982472301E-1,
+0.978948355,
+0.414122880
784+0.765560031,
+0.402232409
789+0.126401901,
+0.409725308,
+0.290748894,
+0.746052206,
+0.638841391E-1,
+0.621300340E-1,
+0.121626973,
+0.372182906,
+0.519970298
792+0.290748894,
+0.746052206,
+0.621300340E-1,
+0.638841391E-1,
+0.126401901,
+0.519970298,
+0.372182906,
+0.409725308,
+0.121626973
798+0.126401901,
+0.638841391E-1,
+0.290748894,
+0.121626973
803+0.734670043,
+0.172342002,
+0.456180871,
+0.818909645
806+0.734670043,
+0.818909645,
+0.456180871,
+0.172342002
812+0.456180871,
+0.818909645
817+0.359283090,
+0.580518842E-1,
+0.714211226,
+0.970433891,
+0.956873477,
+0.959856868,
+0.826061428,
+0.260433555,
+0.383478105
820+0.970433891,
+0.260433555,
+0.383478105,
+0.959856868,
+0.956873477,
+0.359283090,
+0.826061428,
+0.714211226,
+0.580518842E-1
826+0.260433555,
+0.714211226,
+0.359283090,
+0.956873477,
+0.959856868,
+0.580518842E-1,
+0.970433891,
+0.826061428
831+0.369260490,
+0.139049888,
+0.495823562,
+0.131693840,
+0.219791591
834+0.219791591,
+0.131693840,
+0.369260490,
+0.495823562,
+0.139049888
840+0.219791591,
+0.369260490,
+0.495823562,
+0.139049888,
+0.131693840
- Test:
- test_pm_arrayShuffle
- Todo:
- Low Priority: This generic interface can be extended to 2D input objects.
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.
-
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.
-
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.
- Copyright
- Computational Data Science Lab
- Author:
- Amir Shahmoradi, September 1, 2017, 12:00 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas Austin
Definition at line 145 of file pm_arrayShuffle.F90.