Skip to content

Instantly share code, notes, and snippets.

@Xliff
Created January 14, 2020 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xliff/ca96e9b018fadf0716e86facf4471502 to your computer and use it in GitHub Desktop.
Save Xliff/ca96e9b018fadf0716e86facf4471502 to your computer and use it in GitHub Desktop.
Random String Implementation in NQP

Would this be good enough as a generator for temporary filenames? \

nqp::srand(nqp::floor_n(nqp::mul_n(nqp::time_n(),10000)));
my $filechars := 'abcdefghijklmnopqrstuvwxyz0123456789';

my $chr := 20;
my $tmpnam := '';

while $chr {
  my $rc := nqp::floor_n(nqp::rand_n(nqp::chars($filechars)));
  $tmpnam := nqp::concat(
    $tmpnam,
    nqp::substr($filechars, $rc, 1)
  );
  $chr--;
}

say($tmpnam);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment