Skip to content

Instantly share code, notes, and snippets.

@masak
Forked from moritz/gen.pl
Created February 15, 2012 15:00
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 masak/1836395 to your computer and use it in GitHub Desktop.
Save masak/1836395 to your computer and use it in GitHub Desktop.
Generate random, balanced bracket strings
sub gen(Int $c = 6) {
my @l = '[' xx $c;
my @r = ']' xx $c;
my $s = '';
$s ~= (@l == @r ?? @l
!! (@l + @r).rand < @l
?? @l
!! @r).shift
while @l || @r;
$s;
}
say gen;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment