How to implement a random text output in Java?

There is a code that outputs random text from the array:
String[] texts = {"Hello", "Bye", "seen"};
Random Random = new Random ();
int pos = random.nextInt(texts.length);
System.out.print(texts[pos]);


The issue is that I want to display a random whole sentences which will be quite a lot (about 1000), and I understand that they are not to prescribe everything in the array separated by commas. Tell me how it is better to implement?

Can be to create a file where each line is one sentence, and randomly display a string from a file?

Advise how to implement? If you have examples, I would be very grateful.
June 14th 19 at 20:41
2 answers
June 14th 19 at 20:43
Solution
June 14th 19 at 20:45
Well, something like
String[] texts = {"Hello", "Bye", "seen"};
 Random Random = new Random();
 for (int i = 0; i < 10000; i++) {
 int pos = random.nextInt(texts.length);
 if (i % 10 == 0) {
 System.out.print(texts[pos] + "\n");
 } else {
 System.out.print(texts[pos] + " ");
}
 }

Add any conditions, add dot and comma.
What is not understood, will have to register each sentence in the array? - Lafayette.Hickle2 commented on June 14th 19 at 20:48
It seems I did not understand you, you want what would you have suggestions was compiled from the words in the array? Or that would be all quite by accident really happened and that would not be belieberboy? - maverick.Romaguera commented on June 14th 19 at 20:51
can array, can file to register still have)
I would also add the condition that the first word should be upper case, and in the end was the point. - constantin_Olson commented on June 14th 19 at 20:54
I meant that there are for example 100 coherent sentences for example, "tonight will be cold, stay home" and in the same spirit 99 offers. And here they are displayed randomly. How best to implement? Not to register 100 or more long sentences in the array? - Lafayette.Hickle2 commented on June 14th 19 at 20:57
I meant that there are for example 100 coherent sentences for example, "tonight will be cold, stay home" and in the same spirit 99 offers. And here they are displayed randomly. How best to implement? Not to register 100 or more long sentences in the array? - Lafayette.Hickle2 commented on June 14th 19 at 21:00
Yes 100 is possible and in the mountains to write that much. Especially because this is an educational example. And so in the database I usually write. In the file write something quite strange. I just don't understand the ultimate goal. If this training example, then podkluchit built-in database, for example H2. When you download the app, vistavlaite script 100 predlojenii + id. Then randomly get a proposal id. - constantin_Olson commented on June 14th 19 at 21:03
and it can be an example or a link in Russian how to display randomly from the database? - Lafayette.Hickle2 commented on June 14th 19 at 21:06
I had in mind that id you generate through
int pos = random.nextInt
And then make
Select FROM tablitsami WHERE id = pos
- constantin_Olson commented on June 14th 19 at 21:09

Find more questions by tags Java