Page tree

Release 5.0.1

Contents:

The `RAND` function generates a random real number between 0 and 1. This function uses no parameters. Generated values are of Decimal type and have fifteen digits of precision after the decimal point. If you want to see all digits in the generated value, you might need to apply a different number format. See NUMFORMAT Function.

Basic Usage

`derive type:single value: RAND() as:'random'`

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

Syntax and Arguments

There are no arguments for this function.

Examples

Example - Random values

In the following example, the source is simply the `source` column, and the `random` column is generated by the `RAND` function:

`derive type:single value:RAND() as:'random'`

sourcerandom
A

`0.516845703365675`

B

`0.71118736300207`

C

`0.758686066027118`

D

`0.640146255791255`

Example - Type check functions

The `RAND` function is typically used to introduce randomness of some kind in your data. In the following example, it is used to perform sampling within your wider dataset.

Tip: Keep in mind that for larger datasets the application displays only a sample of them. This method of randomization is applied when the panel is applied to the full dataset during job execution.

Source:

You want to extract a random sample of 20% of your set of orders for further study:

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

Transform:

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

`derive type:single value:round(RAND() * 10) as:'random'`

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`:

`keep row:(random > 8)`

Results:

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

OrderIdQtyProdIdrandom
100580Tiny Widgets9
1007100Tiny Widgets10

• Page:
• Page:
• Page:
• Page:
• Page:
• Page:
• Page:
• Page:
• Page:
• Page: