Last active
December 22, 2015 02:08
-
-
Save nanis/6400980 to your computer and use it in GitHub Desktop.
Pick a project name by combining two randomly picked words from a word list.
Usage: `melodious-castlet.pl /usr/share/dict/words`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# Copyright (C) 2013 A. Sinan Unur | |
# http://www.perlfoundation.org/artistic_license_2_0 | |
use 5.012; | |
use strict; | |
use warnings; | |
use warnings qw(FATAL utf8); | |
use open qw(:std :utf8); | |
use File::Slurp qw( read_file ); | |
run(@ARGV); | |
sub run { | |
@_ or die "Need path to word file\n"; | |
my $filename = shift; | |
open my $words_fh, '<', $filename | |
or die "Cannot open word file '$filename': $!"; | |
my $words = read_file( | |
$words_fh, | |
array_ref => 1, | |
'chomp' => 1, | |
blk_size => 4_000_000, | |
); | |
close $words_fh | |
or die "Cannot close word file '$filename': $!"; | |
say join('-', pick($words)); | |
return; | |
} | |
sub pick { | |
my $set = shift; | |
my $j = int rand(@$set); | |
my $k = int rand(@$set - 1); | |
$k += ($k >= $j); | |
return @{ $set }[$j, $k]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment