Created
September 23, 2014 10:38
-
-
Save atleastimtrying/8ce60ccca753972b2356 to your computer and use it in GitHub Desktop.
a while?
This file contains hidden or 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
I need 100 usernames some may fail the test | |
def get_usernames | |
response = [] | |
#loop | |
name = random_name() | |
response << random_name unless User.find(username: name) | |
#end loop | |
response | |
end |
MrJaba
commented
Sep 23, 2014
def get_usernames(desired_names=100)
names = (10*desired_names).times{ random_name }
existing = User.all.pluck(:username)
names = names - existing
names_still_needed = desired_names - names.length
if names < desired_names
names += get_usernames(names_still_needed)
else
names
end
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment