Skip to content

Instantly share code, notes, and snippets.

@moritz
Created February 15, 2012 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save moritz/1836329 to your computer and use it in GitHub Desktop.
Save moritz/1836329 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.shift
!! (@l + @r).rand < @l
?? @l.shift
!! @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