I have a table xyz and there are 5 rows in it. And, I have a function which returns one row from xyz table sort by randomly to the user and then user adds a suggestions to it. so, the suggestions count increased.
Table xyz is like
id | suggestions
----------+--------------
276 | 0
111 | 0
222 | 0
333 | 0
444 | 0
simple function which currently I have is like this
SELECT * FROM xyz
ORDER BY RANDOM()
But my aim is to get at least 3 suggestions on all of the rows, and then any row can have any number of suggestions. so, if each time one row can be selected randomly with equal probability that will do the job. so, in the first 5 instance one row of the table will be selected and once all of them will be selected, then the process repeat again with equal probability of all the rows.
What I don't want is that - one row suggestions 4, but other row suggestions less than 3.
so, if function is called 15 times, I want it to be like this
id | suggestions
----------+--------------
276 | 3
111 | 3
222 | 3
333 | 3
444 | 3
.....
but not like this
id | suggestions
----------+--------------
276 | 1
111 | 0
222 | 5
333 | 6
444 | 3
.....