Corey
Corey

Reputation: 1059

Scala Random.nextString(int) returning question marks

Whenever I use Random.nextString(int), I get a String of questions marks (??????). I've tried using creating an instance of Random and using a seed, but nothing works. I am using Scala 2.10.5. Anyone know what the issue is?

Upvotes: 0

Views: 547

Answers (1)

Régis Jean-Gilles
Régis Jean-Gilles

Reputation: 32719

In most terminals, when a character is not displayable (there are a lot of existing characters, and you cannot remotely hope to have them all in the font used by your terminal), it will print a question mark instead. Because the string is random, you are very likely to have the vast majority of them be non displayable (and thus rendered as a sequence of question marks).

So the strings are valid, they are indeed random (not just a series of question marks), and this is all just a rendering issue. You can easily check that their content really is different each time by displaying the character codes (something like println(myString.map(_.toInt)) will do).

Upvotes: 4

Related Questions