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

Generate and return a randomly-uniform selected sequence of elements from a scalar character or integer range specified via the input limits [start, stop].
More...

Detailed Description

Generate and return a randomly-uniform selected sequence of elements from a scalar character or integer range specified via the input limits [start, stop].

Should the sequence elements be unique, the length of the output sequence must be smaller than or equal to the specified range as [start, stop].

Parameters
[in]count: The input non-negative scalar integer of default kind IK, representing the length of the output sequence of choices in the range specified by [start, stop].
If unique = .true., the condition count <= len(getRange(start, stop, step)) or count <= size(getRange(start, stop, step)) must hold to ensure uniqueness of the elements of the output sequence.
[in]start: See the documentation of the corresponding argument of setChange(rng, change, start, stop, step, unique).
[in]stop: See the documentation of the corresponding argument of setChange(rng, change, start, stop, step, unique).
[in]step: See the documentation of the corresponding argument of setChange(rng, change, start, stop, step, unique).
[in]unique: See the documentation of the corresponding argument of setChange(rng, change, start, stop, step, unique).
(optional, default = .false._LK)
Returns
change : The output vector of size count,
  1. type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64),
or a scalar of,
  1. type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) of length count,
whose elements are uniformly randomly selected from within the range getRange(start, stop, step).


Possible calling interfaces

change = getChange(count, start, stop, step, unique = unique)
Generate and return a randomly-uniform selected sequence of elements from a scalar character or integ...
This module contains procedures and generic interfaces for selecting uniformly-distributed random cho...
Warning
All warnings and conditions associated with getRange(start, stop, step) and setChoice(start, stop, step) equally hold for the procedures of this generic interface.
The length of the resulting sequence from the specified range (start, stop, step) must not be zero.
These conditions are verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
Remarks
The procedures under discussion are impure.
See also
isHead
getChange
setChange
getChoice
setChoice
getUnifRand
setUnifRand
getShuffled
setShuffled
getRemapped
setRemapped


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_arrayRange, only: getRange
10 use pm_arrayChoice, only: getChoice
11 use pm_distUnif, only: getUnifRand
12 use pm_arrayChange, only: getChange
13
14 implicit none
15
16 integer(IK) :: count, itry, ntry = 10
17 type(display_type) :: disp
18 disp = display_type(file = "main.out.F90")
19
20 block
21 integer(IK) :: step
22 character(:), allocatable :: start, stop, change
23
24 do itry = 1, 2
25 call disp%skip
26 call disp%show("count = getChoice([1, 2]); start = 'A'; stop = 'A'; step = getChoice([-1, 1])")
27 count = getChoice([1, 2]); start = 'A'; stop = 'A'; step = getChoice([-1, 1])
28 call disp%show("count")
29 call disp%show( count )
30 call disp%show("change = getChange(count, start, stop, step)")
31 change = getChange(count, start, stop, step)
32 call disp%show("change")
33 call disp%show( change, deliml = SK_"""" )
34 end do
35
36 do itry = 1, ntry
37
38 call disp%skip
39 call disp%show("count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1")
40 count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
41 call disp%show("count")
42 call disp%show( count )
43 call disp%show("change = getChange(count, start, stop, step)")
44 change = getChange(count, start, stop, step)
45 call disp%show("change")
46 call disp%show( change, deliml = SK_"""" )
47
48 call disp%skip
49 call disp%show("count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1")
50 count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
51 call disp%show("count")
52 call disp%show( count )
53 call disp%show("change = getChange(count, start, stop, step, unique = .true._LK)")
54 change = getChange(count, start, stop, step, unique = .true._LK)
55 call disp%show("change")
56 call disp%show( change, deliml = SK_"""" )
57
58 call disp%skip
59 call disp%show("count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3")
60 count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
61 call disp%show("count")
62 call disp%show( count )
63 call disp%show("change = getChange(count, start, stop, step, unique = .true._LK)")
64 change = getChange(count, start, stop, step, unique = .true._LK)
65 call disp%show("change")
66 call disp%show( change, deliml = SK_"""" )
67
68 end do
69 end block
70
71 block
72 use pm_kind, only: IKG => IK ! all integer kinds are supported.
73 integer(IKG) :: step
74 integer(IKG), allocatable :: start, stop, change(:)
75 do itry = 1, ntry
76
77 call disp%skip
78 call disp%show("count = getUnifRand(1, 10); start = 0; stop = 9; step = 1")
79 count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
80 call disp%show("count")
81 call disp%show( count )
82 call disp%show("change = getChange(count, start, stop, step)")
83 change = getChange(count, start, stop, step)
84 call disp%show("change")
85 call disp%show( change, deliml = SK_"""" )
86
87 call disp%skip
88 call disp%show("count = getUnifRand(5, 10); start = 9; stop = -9; step = -2")
89 count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
90 call disp%show("count")
91 call disp%show( count )
92 call disp%show("change = getChange(count, start, stop, step, unique = .true._LK)")
93 change = getChange(count, start, stop, step, unique = .true._LK)
94 call disp%show("change")
95 call disp%show( change, deliml = SK_"""" )
96
97 call disp%skip
98 call disp%show("count = getUnifRand(5, 15); start = 5; stop = 1; step = -2")
99 count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
100 call disp%show("count")
101 call disp%show( count )
102 call disp%show("change = getChange(count, start, stop, step, unique = .false._LK)")
103 change = getChange(count, start, stop, step, unique = .false._LK)
104 call disp%show("change")
105 call disp%show( change, deliml = SK_"""" )
106
107 end do
108 end block
109
110end program example
Select a single (or multiple) element(s) from the input array of intrinsic type of arbitrary kind ran...
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.
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 procedures and generic interfaces for selecting uniformly-distributed or arbitra...
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...
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 = getChoice([1, 2]); start = 'A'; stop = 'A'; step = getChoice([-1, 1])
3count
4+1
5change = getChange(count, start, stop, step)
6change
7"A"
8
9count = getChoice([1, 2]); start = 'A'; stop = 'A'; step = getChoice([-1, 1])
10count
11+2
12change = getChange(count, start, stop, step)
13change
14"AA"
15
16count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
17count
18+7
19change = getChange(count, start, stop, step)
20change
21"DFFCEBF"
22
23count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
24count
25+1
26change = getChange(count, start, stop, step, unique = .true._LK)
27change
28"C"
29
30count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
31count
32+7
33change = getChange(count, start, stop, step, unique = .true._LK)
34change
35"zMk_bGS"
36
37count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
38count
39+7
40change = getChange(count, start, stop, step)
41change
42"BCDBECC"
43
44count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
45count
46+1
47change = getChange(count, start, stop, step, unique = .true._LK)
48change
49"F"
50
51count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
52count
53+10
54change = getChange(count, start, stop, step, unique = .true._LK)
55change
56"VetSJGkAM\"
57
58count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
59count
60+5
61change = getChange(count, start, stop, step)
62change
63"BDFFD"
64
65count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
66count
67+6
68change = getChange(count, start, stop, step, unique = .true._LK)
69change
70"DCBAFE"
71
72count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
73count
74+8
75change = getChange(count, start, stop, step, unique = .true._LK)
76change
77"ASh_\Jqb"
78
79count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
80count
81+7
82change = getChange(count, start, stop, step)
83change
84"EEDACFF"
85
86count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
87count
88+3
89change = getChange(count, start, stop, step, unique = .true._LK)
90change
91"EBD"
92
93count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
94count
95+5
96change = getChange(count, start, stop, step, unique = .true._LK)
97change
98"MzkJw"
99
100count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
101count
102+10
103change = getChange(count, start, stop, step)
104change
105"EAFACABEAE"
106
107count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
108count
109+6
110change = getChange(count, start, stop, step, unique = .true._LK)
111change
112"DECABF"
113
114count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
115count
116+5
117change = getChange(count, start, stop, step, unique = .true._LK)
118change
119"Gzqn_"
120
121count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
122count
123+7
124change = getChange(count, start, stop, step)
125change
126"ABEFBED"
127
128count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
129count
130+5
131change = getChange(count, start, stop, step, unique = .true._LK)
132change
133"FCBED"
134
135count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
136count
137+7
138change = getChange(count, start, stop, step, unique = .true._LK)
139change
140"kPJwGtS"
141
142count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
143count
144+8
145change = getChange(count, start, stop, step)
146change
147"BBCBABFA"
148
149count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
150count
151+3
152change = getChange(count, start, stop, step, unique = .true._LK)
153change
154"CEF"
155
156count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
157count
158+7
159change = getChange(count, start, stop, step, unique = .true._LK)
160change
161"zqPhn_Y"
162
163count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
164count
165+2
166change = getChange(count, start, stop, step)
167change
168"FC"
169
170count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
171count
172+1
173change = getChange(count, start, stop, step, unique = .true._LK)
174change
175"B"
176
177count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
178count
179+8
180change = getChange(count, start, stop, step, unique = .true._LK)
181change
182"hGPVM_\w"
183
184count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
185count
186+4
187change = getChange(count, start, stop, step)
188change
189"ABCA"
190
191count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
192count
193+6
194change = getChange(count, start, stop, step, unique = .true._LK)
195change
196"BFECDA"
197
198count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
199count
200+10
201change = getChange(count, start, stop, step, unique = .true._LK)
202change
203"ewk\nDJSMV"
204
205count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
206count
207+5
208change = getChange(count, start, stop, step)
209change
210"CBCCF"
211
212count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
213count
214+2
215change = getChange(count, start, stop, step, unique = .true._LK)
216change
217"DA"
218
219count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
220count
221+9
222change = getChange(count, start, stop, step, unique = .true._LK)
223change
224"D\PAnkSJw"
225
226count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
227count
228+4
229change = getChange(count, start, stop, step)
230change
231"+3", "+4", "+2", "+6"
232
233count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
234count
235+7
236change = getChange(count, start, stop, step, unique = .true._LK)
237change
238"+1", "-7", "-1", "-3", "+7", "+5", "-5"
239
240count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
241count
242+6
243change = getChange(count, start, stop, step, unique = .false._LK)
244change
245"+1", "+3", "+3", "+5", "+3", "+1"
246
247count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
248count
249+2
250change = getChange(count, start, stop, step)
251change
252"+0", "+3"
253
254count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
255count
256+9
257change = getChange(count, start, stop, step, unique = .true._LK)
258change
259"+5", "-7", "+3", "-3", "-9", "+7", "-5", "+9", "-1"
260
261count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
262count
263+7
264change = getChange(count, start, stop, step, unique = .false._LK)
265change
266"+1", "+5", "+5", "+3", "+5", "+5", "+1"
267
268count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
269count
270+4
271change = getChange(count, start, stop, step)
272change
273"+1", "+4", "+9", "+9"
274
275count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
276count
277+10
278change = getChange(count, start, stop, step, unique = .true._LK)
279change
280"+1", "-5", "-9", "+9", "+5", "+7", "-3", "+3", "-7", "-1"
281
282count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
283count
284+14
285change = getChange(count, start, stop, step, unique = .false._LK)
286change
287"+3", "+5", "+1", "+3", "+3", "+3", "+1", "+3", "+1", "+3", "+3", "+5", "+5", "+1"
288
289count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
290count
291+3
292change = getChange(count, start, stop, step)
293change
294"+2", "+3", "+7"
295
296count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
297count
298+5
299change = getChange(count, start, stop, step, unique = .true._LK)
300change
301"+5", "-1", "-9", "-3", "-7"
302
303count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
304count
305+10
306change = getChange(count, start, stop, step, unique = .false._LK)
307change
308"+5", "+1", "+1", "+5", "+1", "+3", "+3", "+3", "+5", "+1"
309
310count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
311count
312+9
313change = getChange(count, start, stop, step)
314change
315"+3", "+4", "+3", "+0", "+7", "+7", "+5", "+9", "+0"
316
317count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
318count
319+5
320change = getChange(count, start, stop, step, unique = .true._LK)
321change
322"+1", "-3", "-5", "-9", "+3"
323
324count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
325count
326+6
327change = getChange(count, start, stop, step, unique = .false._LK)
328change
329"+5", "+1", "+3", "+5", "+3", "+3"
330
331count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
332count
333+9
334change = getChange(count, start, stop, step)
335change
336"+4", "+2", "+3", "+9", "+0", "+7", "+6", "+8", "+5"
337
338count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
339count
340+5
341change = getChange(count, start, stop, step, unique = .true._LK)
342change
343"-3", "-1", "-5", "-9", "+1"
344
345count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
346count
347+9
348change = getChange(count, start, stop, step, unique = .false._LK)
349change
350"+3", "+1", "+1", "+5", "+3", "+1", "+5", "+3", "+5"
351
352count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
353count
354+10
355change = getChange(count, start, stop, step)
356change
357"+6", "+1", "+1", "+4", "+9", "+0", "+7", "+3", "+5", "+9"
358
359count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
360count
361+6
362change = getChange(count, start, stop, step, unique = .true._LK)
363change
364"+9", "-5", "+3", "-9", "+7", "+1"
365
366count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
367count
368+10
369change = getChange(count, start, stop, step, unique = .false._LK)
370change
371"+3", "+3", "+3", "+1", "+3", "+5", "+5", "+1", "+5", "+3"
372
373count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
374count
375+1
376change = getChange(count, start, stop, step)
377change
378"+0"
379
380count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
381count
382+7
383change = getChange(count, start, stop, step, unique = .true._LK)
384change
385"-9", "-3", "+9", "+3", "+5", "-5", "+7"
386
387count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
388count
389+8
390change = getChange(count, start, stop, step, unique = .false._LK)
391change
392"+3", "+3", "+3", "+5", "+1", "+3", "+1", "+3"
393
394count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
395count
396+9
397change = getChange(count, start, stop, step)
398change
399"+2", "+5", "+5", "+7", "+4", "+6", "+8", "+8", "+6"
400
401count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
402count
403+9
404change = getChange(count, start, stop, step, unique = .true._LK)
405change
406"+3", "-7", "+5", "-5", "+7", "-3", "-9", "+9", "+1"
407
408count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
409count
410+10
411change = getChange(count, start, stop, step, unique = .false._LK)
412change
413"+5", "+1", "+3", "+3", "+5", "+1", "+3", "+1", "+5", "+1"
414
415count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
416count
417+4
418change = getChange(count, start, stop, step)
419change
420"+8", "+2", "+4", "+2"
421
422count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
423count
424+9
425change = getChange(count, start, stop, step, unique = .true._LK)
426change
427"+7", "-3", "+3", "+5", "-7", "-9", "+9", "+1", "-5"
428
429count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
430count
431+9
432change = getChange(count, start, stop, step, unique = .false._LK)
433change
434"+3", "+1", "+3", "+5", "+5", "+1", "+3", "+3", "+3"
435
Test:
test_pm_arrayChange
Todo:
The input argument step can be made optional.
Currently, it is a required argument to avoid testing complexities in the case of input real-valued ranges.


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, Monday March 6, 2017, 3:22 pm, Institute for Computational Engineering and Sciences (ICES), The University of Texas at Austin.

Definition at line 138 of file pm_arrayChange.F90.


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