03.04.2013, 18:25
@leonardo1434: i think he needs some function to return a random line from a file
yours returns an already known line
@MP2: i think i might have a better optimized code here:
Now, this will loop through all the file lines (by reading them), then gets a random value between 0 - 2
if the random value is 1 then it'll return the last readed line, so in short u'll have a chance on three every iteration (u can increase it in random call)
yours returns an already known line
@MP2: i think i might have a better optimized code here:
pawn Code:
stock ReadFileRandomLine(filename[])
{
new File:file = fopen(filename, io_read);
while(fread(file, str))
{
if(random(3) == 1)
{
fclose(file);
src[strlen(src) - 1] = 0;
return src;
}
}
fclose(file);
src[strlen(src) - 1] = 0;
return src;
}
if the random value is 1 then it'll return the last readed line, so in short u'll have a chance on three every iteration (u can increase it in random call)