What's the best way to return a random line in a text file using C?
Posted
by jeremy Ruten
on Stack Overflow
See other posts from Stack Overflow
or by jeremy Ruten
Published on 2008-10-24T01:56:00Z
Indexed on
2010/05/28
23:52 UTC
Read the original article
Hit count: 246
What's the best way to return a random line in a text file using C? It has to use the standard I/O library (<stdio.h>
) because it's for Nintendo DS homebrew.
Clarifications:
- Using a header in the file to store the number of lines won't work for what I want to do.
- I want it to be as random as possible (the best being if each line has an equal probability of being chosen as every other line.)
- The file will never change while the program is being run. (It's the DS, so no multi-tasking.)
© Stack Overflow or respective owner