removed unnecessary static_cast
refactored random code generator to allow for repeated values