Mark accepted: Random with Units Proposal (#3377)

* Mark Accepted: Random with Units Proposal

* add semantic changes to 'random' in /spec

* fix wording for floating point and range for ints in draft 1.1
This commit is contained in:
Goodwine 2022-08-17 18:17:45 -07:00 committed by GitHub
parent 898d716967
commit c4bab9dc6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 5 deletions

View File

@ -0,0 +1,9 @@
## Draft 1.1
* Replace floating-point wording for simply "number".
* Update integer return value range from `[1, $limit)` to `[1, $limit]`.
## Draft 1
* Initial draft.

View File

@ -1,6 +1,6 @@
# Random With Units: Draft 1
# Random With Units: Draft 1.1
*([Issue](https://github.com/sass/sass/issues/1890))*
*([Issue](https://github.com/sass/sass/issues/1890), [Changelog](random-with-units.changes.md))*
This proposal modifies the behavior of the built-in [`math.random()`][random]
function to return a number with matching units to the numeric argument it
@ -72,14 +72,14 @@ unit-based arithmetic.
The `math.random()` function can take an optional parameter `$limit` which
defaults to `null`.
* If `$limit` is `null` then return a pseudo-random floating-point number in the
range `[0, 1)`.
* If `$limit` is `null` then return a pseudo-random unitless number whose value
is in the range `[0, 1)`.
> Example: `math.random() => 0.1337001337`
* If `$limit` is an **integer** [number] greater than zero:
* Return a pseudo-random integer in the range `[1, $limit)` with the same
* Return a pseudo-random integer in the range `[1, $limit]` with the same
[units] as `$limit`.
> Examples:

View File

@ -487,3 +487,23 @@ random($limit: null)
```
This function is also available as a global function named `random()`.
* If `$limit` is `null` then return a pseudo-random unitless number whose value
is in the range `[0, 1)`.
> Example: `math.random() => 0.1337001337`
* If `$limit` is an **integer** [number] greater than zero:
* Return a pseudo-random integer in the range `[1, $limit]` with the same
[units] as `$limit`.
> Examples:
> - `math.random(123) => 87`
> - `math.random(123px) => 43px`
> - `math.random(500%) => 238%`
* Otherwise throw an error.
[number]: https://sass-lang.com/documentation/values/numbers
[units]: https://sass-lang.com/documentation/values/numbers#units