Skip to content

Instantly share code, notes, and snippets.

@DickyT
Last active December 3, 2015 20:13
Show Gist options
  • Save DickyT/20c2e063adb93a1a3923 to your computer and use it in GitHub Desktop.
Save DickyT/20c2e063adb93a1a3923 to your computer and use it in GitHub Desktop.
Procedure GenerateDraw ( n )
INPUT: n, the length of the random array
OUTPUT: result_array, the array contains unique random integers of length n
result_array <- CREATE and array of length n
loop n times {
current_rand = 0
check_pass = True
while current_rand == 0 or check_pass == False {
current_rand = GENERATE a random integer between 1 and 49
for each each_int in result_array {
if each_int == current_rand {
check_pass = False
break
}
else {
check_pass = True
}
}
}
if check_pass == True {
ADD value current_rand to the end of array result_array
}
else {
throw new Exception("whatever")
}
}
return result_array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment