Get random line (optimized)

by Ricardo “Rudxain” Fernández Serrata

Version 1 (January 27, 2023)

Download (72 downloads)

Shows how to get a random line of text from a file, without shuffle()

Tips:
- Only use `split` when the flow reads or re-reads a file.
NEVER use `split` repeatedly on the same text, save its output to a variable, to avoid extra processing.

- Don't repeatedly read a file if it hasn't been modified, only read when the file gets updated.

- Remember that `split` assumes `"\n"` is a delimiter, not a terminator. If \n is used to end every line (including EOF), the returned array will have an empty string at the end.

LICENSE: https://unlicense.org

4.0 average rating from 1 reviews

5 stars
0
4 stars
1
3 stars
0
2 stars
0
1 star
0
Reports
0

Rate and review within the app in the Community section.