Generating random words in Java?

前端 未结 6 1705
抹茶落季
抹茶落季 2021-02-14 09:47

I wrote up a program that can sort words and determine any anagrams. I want to generate an array of random strings so that I can test my method\'s runtime.

publi         


        
6条回答
  •  有刺的猬
    2021-02-14 10:33

    If you want to generate random words of a given length, you'll either need an algorithm to determine if a given string is a word (hard), or access to a word list of all the words in a given language (easy). If it helps, here's a list of every word in the Scrabble dictionary.

    Once you have a list of all words in a language, you can load those words into an ArrayList or other linear structure. You can then generate a random index into that list to get the random word.

提交回复
热议问题