Skip to content

Commit a10ab15

Browse files
authored
Create Compare.RandomInt64.pq
1 parent 9aa68ca commit a10ab15

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
let
2+
/* Build a bunch of random numbers with different rounding modes to compare distribution statistics. */
3+
Rand.Int64 = (min as number, max as number, optional roundingMode as number ) =>
4+
Int64.From(
5+
Number.RandomBetween( min, max ),
6+
"en-us",
7+
roundingMode ?? RoundingMode.TowardZero
8+
),
9+
10+
/* a macro to convert to table */
11+
TestOne = (items as list, optional label as text) as table => [
12+
asTable = Table.FromList(items, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
13+
with_type = Table.TransformColumnTypes( asTable , { { "Column1", Int64.Type } }),
14+
ret = Table.RenameColumns( with_type, { {"Column1", label ?? "Column1"} }, MissingField.Error )
15+
][ret],
16+
17+
Oracle = (obj as any) as text => Text.FromBinary( Json.FromValue(obj) ),
18+
19+
names = List.Buffer( {0..1000} ),
20+
maxIndex = List.Count( names ) - 1,
21+
22+
// build tables
23+
many_up = List.Transform( names, each Rand.Int64( 0, maxIndex, RoundingMode.Up ) ),
24+
many_down = List.Transform( names, each Rand.Int64( 0, maxIndex, RoundingMode.Down ) ),
25+
26+
many_to0 = List.Transform( names, each Rand.Int64( 0, maxIndex, RoundingMode.TowardZero ) ),
27+
many_away0 = List.Transform( names, each Rand.Int64( 0, maxIndex, RoundingMode.AwayFromZero ) ),
28+
many_toeven = List.Transform( names, each Rand.Int64( 0, maxIndex, RoundingMode.ToEven ) ),
29+
30+
// drill down into one, then check column metrics
31+
summary = [
32+
Up = TestOne( many_up, "Up" ),
33+
Down = TestOne( many_down, "Down" ),
34+
TowardZero = TestOne( many_to0, "TowardZero" ),
35+
AwayFromZero = TestOne( many_away0, "AwayFromZero" ),
36+
ToEven = TestOne( many_toeven, "ToEven" )
37+
]
38+
in
39+
summary

0 commit comments

Comments
 (0)