Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from space DEV and version next

...

  • When this value is present, this seed value is used as part of the random number generator such that its output is a set of pseudo-random values, which are consistent between job executions.
  • When the browser is refreshed, the random numbers remain consistent when the seed value is present.
  • This value must be a valid literal Integer value. Column references or functions returning Integer values are not supported. 

D s
snippetBasic

Example:

RAND
d-codelang-syntax
RawWrangletrue
Typeref
showNotetrue
WrangleTextderive type:single value:
rand() as:'random'

rand()

Output: For each row, generate a random number between 0 and 1 in the new random function.

Example with seed value:

d-lang-syntax
RawWrangletrue
Typeref
showNotetrue
WrangleTextderive type:single value: rand(2) as:'random'

rand(2)

Output: For each row, generate a random number between 0 and 1 in the new random function. The generated random set of random values are consistent between job executions and are, in part, governed by the seed value 2.

d-s
snippetSyntax

There are no arguments for this function.

d-lang-syntax
RawWrangletrue
Typesyntax
showNotetrue
WrangleTextderive type:single value: rand([int_value])

rand([int_value])


ArgumentRequired?Data TypeDescription
int_valueNintegerInteger literal

d-s-lang-notes

int_value

Optional Integer literal that is used to generate random numbers. Use of a seed value ensures consistency of output between job executions.

  • Literal numeric values should not be quoted. Quoted values are treated as strings.
  • Multiple columns and wildcards are not supported.

D s
snippetusage

Required?Data TypeExample Value
NoInteger literal14

D s
snippetExamples

Example - Random values

In the following example, the random column is generated by the RAND function:

d-

...

trans
RawWrangletrue
p03Value'random'
Typestep
WrangleTextderive type:single value:

...

rand() as:'random'
p01NameFormula type
p01ValueSingle row formula
p02NameFormula
p02Valuerand()
p03NameNew column name
SearchTermNew formula

sourcerandom
A

0.516845703365675

B

0.71118736300207

C

0.758686066027118

D

0.640146255791255

...

OrderIdQtyProdId
100130Widgets
100210Big Widgets
10035Big Widgets
100440Widgets
100580Tiny Widgets
100620Widgets
1007100Tiny Widgets

TransformTransformation:

You can use the following transform to generate a random integer from one to 10:

d-

...

trans
RawWrangletrue
p03Value'random'
Typestep
WrangleTextderive type:single value:round(

...

rand() * 10) as:'random'
p01NameFormula type
p01ValueSingle row formula
p02NameFormula
p02Valueround(rand() * 10)
p03NameNew column name
SearchTermNew formula

You can now use the following transform to keep only the rows that contain random values that are in the top 20%, where the value is 9 or 10:

d-

...

trans
RawWrangletrue
p03Value(random > 8)
Typestep
WrangleTextkeep row:(random > 8)
p01NameCondition
p01ValueCustom formula
p02NameType of formula
p02ValueCustom single
p03NameCondition
p04ValueKeep matching rows
p04NameAction
SearchTermFilter rows

Results:

Info

NOTE: Since the results are randomized, your results might vary.

...