Pull random line from TXT file as string
Your code looks correct, but you can try it this way too:
<?php
$f_contents = file("random.txt");
$line = $f_contents[rand(0, count($f_contents) - 1)];
?>
Make sure your file has read permissions set, should be CHMOD'd to 644 or 744.