-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce random
JsonPath function
#4
Conversation
README.md
Outdated
@@ -73,6 +73,9 @@ The function output is dictated by the function itself. | |||
| `last()` | Provides the last item of an array | Depends on the array | | |||
| `index(X)` | Provides the item of an array of index: X, if the X is negative, take from backwards | Depends on the array | | |||
| `distinct()`| Provides an array containing only unique items from the input array | List<E> | | |||
| `random()` | Provides the random item of an array | Depends on the array | | |||
|
|||
>>>>>>> Stashed changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>>>>>> Stashed changes |
README.md
Outdated
@@ -73,6 +73,9 @@ The function output is dictated by the function itself. | |||
| `last()` | Provides the last item of an array | Depends on the array | | |||
| `index(X)` | Provides the item of an array of index: X, if the X is negative, take from backwards | Depends on the array | | |||
| `distinct()`| Provides an array containing only unique items from the input array | List<E> | | |||
| `random()` | Provides the random item of an array | Depends on the array | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| `random()` | Provides the random item of an array | Depends on the array | | |
| `random()` | Provides one random item from the array | Depends on the array | |
.collect(Collectors.toList()); | ||
|
||
if (elements.isEmpty()) { | ||
throw new JsonPathException("Aggregation function attempted random value on empty array"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new JsonPathException("Aggregation function attempted random value on empty array"); | |
throw new JsonPathException("Aggregation function attempted to get random item from empty array"); |
throw new JsonPathException("Aggregation function attempted random value on empty array"); | ||
} | ||
|
||
java.util.Random rand = new java.util.Random(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
java.security.SecureRandom
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the reason to change it in this particular context? we do not care about security/predictability and just Random works much faster
java.util.Random rand = new java.util.Random(); | ||
return elements.get(rand.nextInt(elements.size())); | ||
} | ||
throw new JsonPathException("Aggregation function attempted random value using non array"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new JsonPathException("Aggregation function attempted random value using non array"); | |
throw new JsonPathException("Aggregation function attempted to get random item from not array"); |
6f8dc4a
to
500eaf9
Compare
No description provided.