Skip to main content
edited tags
Link
Source Link

Quickly generate random text

I am writing some tests and would like to introduce large chunks of random alphabetic text (just characters a-z) to the input. The way I am generating the text now is like this:

RandomString[length_Integer] :=
    StringJoin[
        Table[
            FromLetterNumber[RandomInteger[{1, 26}]],
            length
        ]
    ]

This works great but is slow: AbsoluteTiming[RandomString[100000]] shows it running in 6.69763 seconds, which is too slow to run on lots of tests.

Does anyone know of a faster way to generate random text?