Cryptographic Random Functions and Array Improvements
We've added four new standard library functions focused on cryptographically secure randomization and array manipulation, plus a breaking change to the runtime API.
New Functions
RandomInt()
Generates cryptographically secure random integers using System.Security.Cryptography.RandomNumberGenerator. Supports both single-argument and range-based calls:
var digit = RandomInt(10) # [0, 10)
var dice = RandomInt(1, 7) # [1, 6]
var year = RandomInt(2000, 2025) # [2000, 2024]
Note that the upper bound is exclusive.
RandomString()
Generates cryptographically secure random strings from a character set. Defaults to alphanumeric, but accepts custom character sets:
var token = RandomString(16) # Alphanumeric
var pin = RandomString(6, "0123456789") # Numeric PIN
var hex = RandomString(32, "0123456789abcdef") # Hexadecimal
RandomChoice()
Selects a random element from an array using cryptographic randomization:
var fruits = ["apple", "banana", "orange"]
var selection = RandomChoice(fruits)
Take()
Returns a new array containing the first n elements without modifying the original. Useful for pagination and limiting results:
var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
var first_five = Take(numbers, 5) # [1, 2, 3, 4, 5]
# Combine with SortByField for top-N queries
var sorted = SortByField(users, "score", "desc")
var top_three = Take(sorted, 3)
Breaking Change: ExecutionContext Renamed
To prevent naming collisions with System.Threading.ExecutionContext, the runtime's ExecutionContext class has been renamed to JyroExecutionContext.
If you're directly using the Jyro runtime API, update your references:
// Before
var context = new ExecutionContext();
// After
var context = new JyroExecutionContext();
If you're not using System.Threading.ExecutionContext directly, a simple find-and-replace is sufficient.