fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.
Fuzion
•
Idioms
•
Idiom # 317: Random string
Idiom # 317: Random string
See
programming-idioms.org
:
Code
alphanum := ["A","B","C","D","E","F","G","H","I","J","K","L","M", "N","O","P","Q","R","S","T","U","V","W","X","Y","Z", "a","b","c","d","e","f","g","h","i","j","k","l","m", "n","o","p","q","r","s","t","u","v","w","x","y","z", "0","1","2","3","4","5","6","7","8","9"] random_string(n) => if n = 0 "" else alphanum[random.next_i32 alphanum.length] + random_string n-1 s := random_string n
What are effects?
Runnable Example
ex317 is alphanum := ["A","B","C","D","E","F","G","H","I","J","K","L","M", "N","O","P","Q","R","S","T","U","V","W","X","Y","Z", "a","b","c","d","e","f","g","h","i","j","k","l","m", "n","o","p","q","r","s","t","u","v","w","x","y","z", "0","1","2","3","4","5","6","7","8","9"] # Create a random provider with the given seed # ensures deterministic sequence of random output for testing simple_random 5945074330984974151 ()-> random_string(n0) => if n0 = 0 "" else alphanum[random.next_i32 alphanum.length] + random_string n0-1 n := 50 for _ in 0..2 do s := random_string n say s
What are effects?
last changed: 2024-07-01
next: NYI: Idiom # 318: Cryptographically secure random number