How to generate a SecureRandom string of length n in Java? [duplicate]
问题 This question already has answers here : How to generate a random alpha-numeric string? (41 answers) Closed last year . I'm generating a random string using: private String generateSafeToken() { SecureRandom random = new SecureRandom(); byte bytes[] = new byte[512]; random.nextBytes(bytes); return bytes.toString(); } This gives a string of length 11 such as [B@70ffc557 . How can I make this above method return a string of a specified length. For example 20 characters? 回答1: I don't understand