In general, so, there is a file where do db.txt data come from

1 Бла1 Бла2 Бла3 2 Бла6 Бла5 Бла4 3 Бла7 Бла8 Бла9 4 Бла12 Бла11 Бла10 

And each number has its own picture. Number, I understand the question ID, and Bla * the correct answers. I click on the start button. I generate a random number v: = Random (3) +1 from 1 to 4. I display a picture according to the number Img.Picture.LoadFromFile ('img / img _' + v + '. Jpg'); Also next to the picture there are 3 text entry fields where the correct answers should be entered. So my task. Get a random number, open the file and find there a line with this number, get the corresponding answers, then compare them with the entered values ​​in the text input fields. If possible, the number already used should be excluded from use. Those. if the number 3 was generated, and the answer is received, so that the number 3 in the next. once it was ignored, but something else was not displayed. Vooot. Please help! Here is my listing:

 v:=Random(3)+1; //Получаем случайное число Img.Picture.LoadFromFile('img/img_'+v+'.jpg'); //Выводим соответствующую картинку AssignFile(fdb,'db.txt'); reset(fdb); //Открываем файл для чтения read(fdb,vid,otv1,otv2,otv3); //Назначаем переменные {Здесь какой-то код, который ищет строку с номером V} 

    2 answers 2

    To the answer of Dex - I apologize for incompetence (specifically with RSLOS - see the wiki - did not understand), however, pseudo-random sequences, generally speaking, do not guarantee the reproducibility of the generated values.

    as a solution to the problem of repeating the question - in order to avoid keeping all the questions in memory as structures, etc. and exclude the appearance of repetitions, create an array (vector) of n values ​​(n is the number of questions, values ​​are from 1 to n or from 0 to n-1, as it is more convenient), use ANY generator of pseudo-random sequences (including "built-in" in Delfi (like there?)). Further so (indexing 1-n is supposed):

    1. Call the value generator from 1 to n. Get the index m.
    2. Select question number FROM CELL WITH INDEX m (let it be k).
    3. Put the value FROM THE CELL WITH INDEX n into the cell with the index m.
    4. Reduce n by 1.
    5. Display the kth question.
    6. If n> 0 then go back to step 1.
      1. Load the file immediately in memory
      2. Keep a list of "sounded questions", enter the indexes there and check each time you generate a new one if there has been such a question already.
      3. You can do it easier, depending on the number of questions, you can use a pseudo-random sequence (for the number 7, there are 3 different things). In this case, there is no need for a list of "questions that have been answered," you can always continue the test from the point where it stopped, repetition is not possible until the whole cycle has passed.

      UPD

      For (1) Ship to the structure (for example, to the list, you can still sort if the questions are not in order) For (2) there are a lot of implementation options, for example:

      1. Loaded everything into memory (as stated in 1), you know the number of questions
      2. Generate a number from (number of questions), take a picture, blah blah blah
      3. Remove a question from the list
      4. For the next question, the generator is already from (number of questions - 1)
      5. And so on

      For (3) English wiki or Russian wiki

      • 1. What does it mean to load a file into memory? 2. I am familiar with this decision, but I am interested in the details of 3 ways. Tell us more about it please! - chuikoff
      • see upd - Dex