-
Notifications
You must be signed in to change notification settings - Fork 4
/
Random.Int64.pq
51 lines (49 loc) · 2.19 KB
/
Random.Int64.pq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
[
/*
Source: https://github.com/ninmonkey/Ninmonkey.PowerQueryLib
About: Randomized Integer between a range. [2021-04-22]
See Also: Number.Round* family of functions, and <https://docs.microsoft.com/en-us/power-query/handlingdocumentation>
*/
fn.Type = type function (
min as (type number meta [
Documentation.FieldCaption = "Min",
Documentation.FieldDescription = "Minimum number",
Documentation.SampleValues = {10, 0.45}
]),
b as (type number meta [
Documentation.FieldCaption = "Max",
Documentation.FieldDescription = "Maximum number",
Documentation.SampleValues = {34, 100.45}
]),
optional culture as (type nullable text meta [
Documentation.FieldCaption = "Culture",
Documentation.FieldDescription = "Culture used to convert number"
]),
optional roundingMode as (type nullable number meta [
Documentation.FieldCaption = "Rounding Mode",
Documentation.FieldDescription = "rounding method",
Documentation.AllowedValues = {
RoundingMode.AwayFromZero, RoundingMode.Down, RoundingMode.ToEven, RoundingMode.TowardZero, RoundingMode.Up}
])
) as table meta [
Documentation.Name = "RandomInt",
Documentation.LongDescription = "Generate a random Integer between two values. Optionally set culture and rounding mode.",
Documentation.Examples = {[
Description = "Generate one value",
Code = "RandomInt(10, 20)",
Result = "11"
]}
],
fn.Impl = (
min as number,
max as number,
optional culture as nullable text,
optional roundingMode as nullable number
) as number =>
Int64.From(
Number.RandomBetween( min, max ),
culture,
roundingMode
),
return = Value.ReplaceType( fn.Impl, fn.Type )
][return]