What is the best way to randomly pick a record/line from a txt or CSV file every time the user clicks a button?
问题 Codeless at the moment, just trying to figure it out to start my project. Say for example I'm creating a dare game. Every time a user clicks the dare button, it should randomly pick a dare from the dare file, either a txt or CSV and display it in a field. Best way to accomplish this? 回答1: Choosing a line from a file, uniformly at random, can be done using the reservoir sampling technique. For each line in the file, choose it at a 1/N chance, where N is the number of lines read so far,