Skip to content

Commit

Permalink
Some fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
rschu1ze committed Mar 11, 2024
1 parent e98c30c commit 27099ce
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 72 deletions.
84 changes: 23 additions & 61 deletions docs/en/sql-reference/functions/random-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,89 +20,55 @@ The random numbers are generated by non-cryptographic algorithms.

## rand

Returns a random UInt32 number.
Returns a random UInt32 number with uniform distribution.

Uses a linear congruential generator with an initial state obtained from the system, which means that while it appears random, it's not truly random and can be predictable if the initial state is known. For scenarios where true randomness is crucial, consider using alternative methods like system-level calls or integrating with external libraries.

### Syntax

```sql
rand()
```

### Parameters
Alias: `rand32`

### Arguments

None.

### Output
### Returned value

Returns a number of type UInt32.

### Implementation details

Uses a linear congruential generator.

### Example

```sql
SELECT rand();
```

```response
1569354847
```

**Note:** The actual output will be a random number, not the specific number shown in the example.

## rand32

Returns a random 32-bit unsigned integer (UInt32) number.

### Syntax

```sql
rand32()
1569354847 -- Note: The actual output will be a random number, not the specific number shown in the example
```

### Parameters

None.

### Output

Returns a number of type UInt32, evenly distributed across the range of all possible UInt32 values.

### Example

```sql
SELECT rand32();
```

```response
2754546224
```

**Note:** The actual output will be a random number, not the specific number shown in the example.

## rand64

Returns a random 64-bit unsigned integer (UInt64) number.
Returns a random UInt64 integer (UInt64) number

### Syntax

```sql
rand64()
```

### Parameters
### Arguments

None.

### Output
### Returned value

Returns a number of type UInt64, evenly distributed across the range of all possible UInt64 values.
Returns a number UInt64 number with uniform distribution.

### Implementation details

The `rand64` function uses a linear congruential generator, which means that while it appears random, it's not truly random and can be predictable if the initial state is known. For scenarios where true randomness is crucial, consider using alternative methods like system-level calls or integrating with external libraries.
Uses a linear congruential generator with an initial state obtained from the system, which means that while it appears random, it's not truly random and can be predictable if the initial state is known. For scenarios where true randomness is crucial, consider using alternative methods like system-level calls or integrating with external libraries.

### Example

Expand All @@ -111,26 +77,24 @@ SELECT rand64();
```

```response
15030268859237645412
15030268859237645412 -- Note: The actual output will be a random number, not the specific number shown in the example.
```

**Note:** The actual output will be a random number, not the specific number shown in the example.

## randCanonical

Returns a random floating-point number of type Float64, evenly distributed within the closed interval.
Returns a random Float64 number.

### Syntax

```sql
randCanonical()
```

### Parameters
### Arguments

None.

### Output
### Returned value

Returns a Float64 value between 0 (inclusive) and 1 (exclusive).

Expand All @@ -141,26 +105,24 @@ SELECT randCanonical();
```

```response
0.3452178901234567
0.3452178901234567 - Note: The actual output will be a random Float64 number between 0 and 1, not the specific number shown in the example.
```

**Note:** The actual output will be a random decimal number between 0 and 1, not the specific number shown in the example.

## randConstant

Generates a single constant column filled with a random value. Unlike `rand`, `randConstant` ensures the same random value appears in every row of the generated column, making it useful for scenarios requiring a consistent random seed across rows in a single query.
Generates a single constant column filled with a random value. Unlike `rand`, this function ensures the same random value appears in every row of the generated column, making it useful for scenarios requiring a consistent random seed across rows in a single query.

### Syntax

```sql
randConstant([x]);
```

### Parameters
### Arguments

- **[x] (Optional):** An optional expression that influences the generated random value. Even if provided, the resulting value will still be constant within the same query execution. Different queries using the same expression will likely generate different constant values.

### Output
### Returned value

Returns a column of type UInt32 containing the same random value in each row.

Expand Down Expand Up @@ -200,12 +162,12 @@ Returns a random Float64 drawn uniformly from interval [`min`, `max`].
randUniform(min, max)
```

### Parameters
### Arguments

- `min` - `Float64` - left boundary of the range,
- `max` - `Float64` - right boundary of the range.

### Output
### Returned value

A random number of type [Float64](/docs/en/sql-reference/data-types/float.md).

Expand Down
16 changes: 8 additions & 8 deletions docs/en/sql-reference/functions/type-conversion-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ Converts a numeric value to String with the number of fractional digits in the o
toDecimalString(number, scale)
```

**Parameters**
**Arguments**

- `number` — Value to be represented as String, [Int, UInt](/docs/en/sql-reference/data-types/int-uint.md), [Float](/docs/en/sql-reference/data-types/float.md), [Decimal](/docs/en/sql-reference/data-types/decimal.md),
- `scale` — Number of fractional digits, [UInt8](/docs/en/sql-reference/data-types/int-uint.md).
Expand Down Expand Up @@ -1261,7 +1261,7 @@ Converts input value `x` to the specified data type `T`. Always returns [Nullabl
accurateCastOrNull(x, T)
```

**Parameters**
**Arguments**

- `x` — Input value.
- `T` — The name of the returned data type.
Expand Down Expand Up @@ -1314,7 +1314,7 @@ Converts input value `x` to the specified data type `T`. Returns default type va
accurateCastOrDefault(x, T)
```

**Parameters**
**Arguments**

- `x` — Input value.
- `T` — The name of the returned data type.
Expand Down Expand Up @@ -1675,7 +1675,7 @@ Same as [parseDateTimeBestEffort](#parsedatetimebesteffort) function but also pa
parseDateTime64BestEffort(time_string [, precision [, time_zone]])
```

**Parameters**
**Arguments**

- `time_string` — String containing a date or date with time to convert. [String](/docs/en/sql-reference/data-types/string.md).
- `precision` — Required precision. `3` — for milliseconds, `6` — for microseconds. Default — `3`. Optional. [UInt8](/docs/en/sql-reference/data-types/int-uint.md).
Expand Down Expand Up @@ -1990,7 +1990,7 @@ Extracts the timestamp component of a [Snowflake ID](https://en.wikipedia.org/wi
snowflakeToDateTime(value[, time_zone])
```

**Parameters**
**Arguments**

- `value` — Snowflake ID. [Int64](/docs/en/sql-reference/data-types/int-uint.md).
- `time_zone`[Timezone](/docs/en/operations/server-configuration-parameters/settings.md/#server_configuration_parameters-timezone). The function parses `time_string` according to the timezone. Optional. [String](/docs/en/sql-reference/data-types/string.md).
Expand Down Expand Up @@ -2026,7 +2026,7 @@ Extracts the timestamp component of a [Snowflake ID](https://en.wikipedia.org/wi
snowflakeToDateTime64(value[, time_zone])
```

**Parameters**
**Arguments**

- `value` — Snowflake ID. [Int64](/docs/en/sql-reference/data-types/int-uint.md).
- `time_zone`[Timezone](/docs/en/operations/server-configuration-parameters/settings.md/#server_configuration_parameters-timezone). The function parses `time_string` according to the timezone. Optional. [String](/docs/en/sql-reference/data-types/string.md).
Expand Down Expand Up @@ -2062,7 +2062,7 @@ Converts a [DateTime](/docs/en/sql-reference/data-types/datetime.md) value to th
dateTimeToSnowflake(value)
```

**Parameters**
**Arguments**

- `value` — Date with time. [DateTime](/docs/en/sql-reference/data-types/datetime.md).

Expand Down Expand Up @@ -2096,7 +2096,7 @@ Convert a [DateTime64](/docs/en/sql-reference/data-types/datetime64.md) to the f
dateTime64ToSnowflake(value)
```

**Parameters**
**Arguments**

- `value` — Date with time. [DateTime64](/docs/en/sql-reference/data-types/datetime64.md).

Expand Down
6 changes: 3 additions & 3 deletions docs/en/sql-reference/functions/url-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Configuration example:
cutToFirstSignificantSubdomain(URL, TLD)
```

**Parameters**
**Arguments**

- `URL` — URL. [String](../../sql-reference/data-types/string.md).
- `TLD` — Custom TLD list name. [String](../../sql-reference/data-types/string.md).
Expand Down Expand Up @@ -209,7 +209,7 @@ Configuration example:
cutToFirstSignificantSubdomainCustomWithWWW(URL, TLD)
```

**Parameters**
**Arguments**

- `URL` — URL. [String](../../sql-reference/data-types/string.md).
- `TLD` — Custom TLD list name. [String](../../sql-reference/data-types/string.md).
Expand Down Expand Up @@ -263,7 +263,7 @@ Configuration example:
firstSignificantSubdomainCustom(URL, TLD)
```

**Parameters**
**Arguments**

- `URL` — URL. [String](../../sql-reference/data-types/string.md).
- `TLD` — Custom TLD list name. [String](../../sql-reference/data-types/string.md).
Expand Down

0 comments on commit 27099ce

Please sign in to comment.