Skip to content

Commit

Permalink
Update names to min max. Remove end_inclusive
Browse files Browse the repository at this point in the history
  • Loading branch information
AdRiley committed Jan 23, 2024
1 parent 8bf8c47 commit 09b4c93
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
20 changes: 10 additions & 10 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Random.enso
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type Random

Arguments:
- min: The minimum value of the range to pick from (inclusive).
- max: The maximum value of the range to pick from (inclusive).
- max: The maximum value of the range to pick from (exclusive).

> Example
Generate a float between 2.3 and 3.4.
Expand Down Expand Up @@ -146,8 +146,8 @@ type Random
Return a `Date` within the specified `Date_Range`.

Arguments:
- start_date: The lower bound of the range to pick from (inclusive).
- end_date: The upper bound of the range to pick from (inclusive).
- min: The lower bound of the range to pick from (inclusive).
- max: The upper bound of the range to pick from (inclusive).

> Example
Generate a random date.
Expand All @@ -156,14 +156,14 @@ type Random

d = Random.date (Date.new 2023 03 01) (Date.new 2023 10 15)
date : Date -> Date -> Boolean -> Date
date start_date:Date end_date:Date end_exclusive=False = Random_Generator.global_random_generator.date start_date end_date end_exclusive
date min:Date max:Date = Random_Generator.global_random_generator.date min max

## GROUP Random
Return a `Time_Of_Day` between `start_time` and `end_time` (inclusive).

Arguments:
- start_time: The lower bound of the range to pick from (inclusive).
- end_time: The upper bound of the range to pick from (inclusive).
- min: The lower bound of the range to pick from (inclusive).
- max: The upper bound of the range to pick from (inclusive).

The generated time is at a granularity of 1 second. Random values are
generated for hours, minutes and seconds. The `nanoseconds` field is
Expand All @@ -178,8 +178,8 @@ type Random
end = Time_Of_Day.new 9 40 2
t = Random.time start end
time : Time_Of_Day -> Time_Of_Day -> Time_Of_Day
time (start_time:Time_Of_Day=(Time_Of_Day.new 0 0 0)) (end_time:Time_Of_Day=(Time_Of_Day.new 23 59 59)) =
Random_Generator.global_random_generator.time start_time end_time
time (min:Time_Of_Day=(Time_Of_Day.new 0 0 0)) (max:Time_Of_Day=(Time_Of_Day.new 23 59 59)) =
Random_Generator.global_random_generator.time min max

## GROUP Random
Return a new UUID.
Expand Down Expand Up @@ -298,8 +298,8 @@ type Random_Generator

## PRIVATE
date : Date -> Date -> Boolean -> Date
date self start_date:Date end_date:Date end_exclusive=True =
date_range = start_date.up_to end_date include_end=end_exclusive.not
date self start_date:Date end_date:Date =
date_range = start_date.up_to end_date include_end=True
date_range.at (self.integer 0 date_range.length)

## PRIVATE
Expand Down
5 changes: 0 additions & 5 deletions test/Base_Tests/src/Random_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ spec = Test.group "Random" <|
dates = 0.up_to 100 . map (_-> Random.date (Date.new 2023 03 01) (Date.new 2023 03 03))
dates.should_contain_the_same_elements_as all_from_small_range

Test.specify "should allow generating random dates, with end_exclusive=True" <|
all_from_small_range = [Date.new 2023 03 01, Date.new 2023 03 02, Date.new 2023 03 03, Date.new 2023 03 04]
dates = 0.up_to 100 . map (_-> Random.date (Date.new 2023 03 01) (Date.new 2023 03 05) end_exclusive=True)
dates.should_contain_the_same_elements_as all_from_small_range

Test.specify "should allow generating random times" <|
Random.set_seed 12345
start = Time_Of_Day.new 8 12 15
Expand Down

0 comments on commit 09b4c93

Please sign in to comment.