Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you generate random token

Tags:

raku

I want to be able to generate a string that contains letters and numbers in Raku. I can't find a module that works.

I want to be able to generate something like this: w6sj7d2j2

like image 273
Hermes Avatar asked Jan 16 '20 23:01

Hermes


Video Answer


1 Answers

say ("a".."z","A".."Z",0..9).flat.roll(8).join;   # M9lldSFC

("a".."z","A".."Z",0..9) specifies the list of characters that you want to occur in your random string.

.flat makes sure the ranges will be flattened to their elements

.roll(8) selects a random element from the list 8 times.

.join concatenates the selected elements from the list into a single string

like image 96
Elizabeth Mattijsen Avatar answered Oct 28 '22 09:10

Elizabeth Mattijsen