L
L
lonata2019-01-07 12:31:31
Java
lonata, 2019-01-07 12:31:31

How to make a query in SQLite according to the random number and percentage method?

I am writing a program in JAVAFX and Scene Builder. database - SQLite. I use DB Browser to browse the database
In SQlite there are two tables: "category1" and "sentences"
In the table "category1" there are 3 columns: "ID" , "question" and "answer". that is, a table with questions and answers.
5c33177b0e152717909203.jpeg
There are two columns in the "sentences" table: "ID" , "sentence"
5c3317fce2448255014489.jpeg
In the Controller class there are two texaria fields where you want to display the text when the button is clicked.

@FXML  private TextArea ta_questText, ta_answerText;

There is a button that calls the method:
@FXML private Button btnRand;
@FXML void randomCard(ActionEvent event) {

}

I want this method to do the following:
- create a 30% and 70% chance
- generate a random number between 0 and 100
- 70% that will generate a number from 0 to 70
- 30% that will generate a number from 70 to 100
- if a number comes up from 0 to 70, then make a query in SQLite, into the "category1" table, take a random number from the ID column and display the text from the "question" and "answer" columns corresponding to this ID in the text fields of the main window
- if a number from 70 falls out up to 100 then make a query in SQlite, in the "sentences" table, take a random number from the ID column and display the text from the "sentence" column corresponding to this ID in one of the text fields in the main program window (both fields are possible)
in other words, 70% chance that random text from the "category1" table will appear in the text fields of the main window,
and a 30% chance that random text from the "sentences" table will appear
How to create such a method?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question