I could have 300 - 400 structures like this. I want the code to show/ask me randomly words so I can memorize those. It is going to be a vocabulary trainer. One solution could be to put the structures in a list and then select an element of the list with some predicate “random pick an element from a list”. I wander if there could be a different solution, avoiding the list?
Nice solution. It doesn’t scale very well as nth_clause/3 is linear. The quickest solution is probably to create a predicate as below, compute the random number and use word(Rnd, Word).
You may also consider this to have a backtracking source of random words. This is different from the above of course as it never returns the same word twice.
Yes, this is the more obvious solution, for a static table of facts. If you add/delete rows you need to re-index it, which is annoying.
What you show with permuting the list is called “sampling without replacement” (as alternative to sampling with replacement), at least in R lingo. Both are useful and needed.