Lumesh rand
Module Documentation
Module Name: rand
You can view help using help rand
.
Function Description: Provides random number generation, random sampling, and randomization operations.
Function Directory
Function Category | Function Name | Call Format | Core Functionality |
---|---|---|---|
Boolean Generation | ratio |
rand.ratio [numerator] [denominator] |
Generate a boolean value based on probability |
String Generation | alpha |
rand.alpha [length] |
Generate a random alphabetic string |
String Generation | alphanum |
rand.alphanum [length] |
Generate a random alphanumeric string |
Numeric Generation | int |
rand.int [min] [max] |
Generate a random integer |
Sampling Operation | choose |
rand.choose [list] |
Randomly select an element from a list |
List Operation | shuffle |
rand.shuffle [list] |
Randomly shuffle the order of a list |
Function Details
1. rand.ratio
- Probability Boolean Generation
Parameter Description:
Parameter Mode | Parameter Type | Description |
---|---|---|
No Parameters | - | Defaults to returning true with 50% probability |
Single Parameter | Float |
Specifies the probability of true (0.0 to 1.0) |
Two Parameters | Integer, Integer |
Specifies probability in numerator/denominator form (e.g., 3 5 means 3/5 probability) |
Return Value: Boolean
Example:
# Basic Call |
2. rand.alpha
- Random Alphabetic String
Parameter Description:
Parameter Mode | Parameter Type | Description |
---|---|---|
No Parameters | - | Returns a single random letter |
Single Parameter | Integer |
Specifies the length of the string to generate |
Return Value: String
Example:
rand.alpha # => "k" |
3. rand.alphanum
- Random Alphanumeric String
Parameter Description:
Parameter Mode | Parameter Type | Description |
---|---|---|
No Parameters | - | Returns a single random letter or digit |
Single Parameter | Integer |
Specifies the length of the string to generate |
Return Value: String
Example:
rand.alphanum # => "7" |
4. rand.int
- Random Integer Generation
Parameter Description:
Parameter Mode | Parameter Type | Description |
---|---|---|
No Parameters | - | Returns a random integer in the entire i64 range |
Single Parameter | Integer |
Returns an integer in the range [0, max] (supports negative numbers) |
Two Parameters | Integer, Integer |
Returns an integer in the range [min, max] |
Return Value: Integer
Example:
rand.int # => -327683491 (example) |
5. rand.choose
- List Random Sampling
Parameter Description:
Parameter | Type | Description |
---|---|---|
1 | List |
The list of data to sample from |
Return Value: Any element from the list (returns None
for an empty list)
Example:
rand.choose [1 2 3] # => 2 |
6. rand.shuffle
- List Randomization
Parameter Description:
Parameter | Type | Description |
---|---|---|
1 | List |
The list of data to randomize |
Return Value: A new list with elements in random order
Example:
ori=list.from(0..12) |
Output Example:
┌───┬───┬───┬────┬───┬───┬───┬───┬───┬────┬───┬───┐ |
Usage Scenario Examples
Batch Generate Test Data:
# Generate 10 random usernames |
Output Example:
+-------------------------+ |