Skip to content

Instantly share code, notes, and snippets.

@mizanRahman
Created August 28, 2018 19:35
Show Gist options
  • Save mizanRahman/0bc0212c44be538a9694877183bd89e6 to your computer and use it in GitHub Desktop.
Save mizanRahman/0bc0212c44be538a9694877183bd89e6 to your computer and use it in GitHub Desktop.
Unique Random Generation
public class UniqueRandomNumberGeneratorImplV2 implements UniqueRandomNumberGenerator {
private SecureRandom random;
@Autowired
public UniqueRandomNumberGeneratorImplV2(SecureRandom random) {
this.random = random;
}
@Override
public String generateRandomUnique(int length) {
return IntStream.range(0, length)
.mapToObj(i -> String.valueOf(random.nextInt(10)))
.collect(Collectors.joining());
}
}
private void writeTextToFile(String path, String content) throws IOException {
FileUtils.writeStringToFile(new File(path),content);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment