mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 06:37:46 +00:00

related to - https://github.com/nushell/nushell/pull/10567 - https://github.com/nushell/nushell/pull/10668 - https://github.com/nushell/nushell/pull/10568 this PR removes mentions to removed commands from https://github.com/nushell/nushell/pull/10567, https://github.com/nushell/nushell/pull/10668 and https://github.com/nushell/nushell/pull/10568. the main change has been introduced with ```nushell sd 'random integer' 'random int' **/*.nu ``` running `rg "$nothing|random integer|to xml .* --pretty"` gives - before ``` modules/random-list/random-list.nu 85:# Generate a random integer list. 95: random integer $range modules/fun/wordle.nu 11: let word = ($words | get (random integer 0..($words | length)) | get column1) benchmarks/random-bytes.nu 5: | each { random integer } sourced/misc/password_generator/ReadMe.md 84:Obviously you can just use the `random chars` or `random integers` commands but I like to have words I can read in my passwords, and I think those generated by this script have sufficient entropy. sourced/misc/password_generator/nupass.nu 43: let random_numbers = (1..$words | par-each { |i| (random integer 0..99) } --threads $threads) 71: return (0..($words - 1) | each { |it| (random integer 0..99 | into string) + ($random_words | get $it) } | reduce { |it , acc| $acc + $it }) 92: | get (random integer 1..($numlines)) 99: let rint = (random integer 1..4) 119: | get (random integer 0..($symbolcharslen - 1)) ``` - after ``` modules/random-list/random-list.nu 85:# Generate a random integer list. sourced/misc/password_generator/ReadMe.md 84:Obviously you can just use the `random chars` or `random integers` commands but I like to have words I can read in my passwords, and I think those generated by this script have sufficient entropy. ```
110 lines
2.9 KiB
Text
110 lines
2.9 KiB
Text
def throw-error [
|
|
error: string
|
|
msg: string
|
|
span: record
|
|
] {
|
|
error make {
|
|
msg: $"(ansi red_bold)($error)(ansi reset)"
|
|
label: {
|
|
text: $msg
|
|
start: $span.start
|
|
end: $span.end
|
|
}
|
|
}
|
|
}
|
|
|
|
# Generate a random boolean list.
|
|
export def "random-list bool" [
|
|
list_length: int, # A length of the list
|
|
--bias (-b): float = 0.5 # A probability of "true"
|
|
] {
|
|
if $bias < 0 or $bias > 1 {
|
|
throw-error "value_error" "must be between 0 and 1" (metadata $bias | get span)
|
|
}
|
|
if $list_length < 0 {
|
|
throw-error "value_error" "must be greater than 0" (metadata $list_length | get span)
|
|
}
|
|
|
|
1..$list_length | each {|it|
|
|
random bool --bias $bias
|
|
}
|
|
}
|
|
|
|
# Generate a random char list.
|
|
export def "random-list chars" [
|
|
list_length: int, # A length of the list
|
|
--length (-l): int = 5 # A length of the string
|
|
] {
|
|
if $list_length < 0 {
|
|
throw-error "value_error" "must be greater than 0" (metadata $list_length | get span)
|
|
}
|
|
if $length < 0 {
|
|
throw-error "value_error" "must be greater than 0" (metadata $length | get span)
|
|
}
|
|
|
|
1..$list_length | each {|it|
|
|
random chars --length $length
|
|
}
|
|
}
|
|
|
|
# Generate a random float list.
|
|
export def "random-list float" [
|
|
list_length: int, # A length of the list
|
|
--range (-r): range # A range of the value
|
|
] {
|
|
if $list_length < 0 {
|
|
throw-error "value_error" "must be greater than 0" (metadata $list_length | get span)
|
|
}
|
|
|
|
1..$list_length | each {|it|
|
|
random float $range
|
|
}
|
|
}
|
|
|
|
# Generate a random dice list.
|
|
export def "random-list dice" [
|
|
list_length: int, # A length of the list
|
|
--roll-count (-r): int = 6, # A roll count
|
|
--side-count (-s): int = 6 # A side count
|
|
] {
|
|
if $list_length < 0 {
|
|
throw-error "value_error" "must be greater than 0" (metadata $list_length | get span)
|
|
}
|
|
if $roll_count < 0 {
|
|
throw-error "value_error" "must be greater than 0" (metadata $roll_count | get span)
|
|
}
|
|
if $side_count < 0 {
|
|
throw-error "value_error" "must be greater than 0" (metadata $side_count | get span)
|
|
}
|
|
|
|
1..$list_length | each {|it|
|
|
random dice --dice $roll_count --sides $side_count
|
|
}
|
|
}
|
|
|
|
# Generate a random integer list.
|
|
export def "random-list int" [
|
|
list_length: int # A length of the list
|
|
--range (-r): range # A range of the value
|
|
] {
|
|
if $list_length < 0 {
|
|
throw-error "value_error" "must be greater than 0" (metadata $list_length | get span)
|
|
}
|
|
|
|
1..$list_length | each {|it|
|
|
random int $range
|
|
}
|
|
}
|
|
|
|
# Generate a random uuid list.
|
|
export def "random-list uuid" [
|
|
list_length: int # A length of the list
|
|
] {
|
|
if $list_length < 0 {
|
|
throw-error "value_error" "must be greater than 0" (metadata $list_length | get span)
|
|
}
|
|
|
|
1..$list_length | each {|it|
|
|
random uuid
|
|
}
|
|
}
|