Getting a random line from a file - and a question!!!
29 10 2007
line = IO.readlines('some_file')
c = rand*line.length.to_i
puts line[c-1]
Very simple logic and it can be easily understood by just looking at the code itself. No explanation needed. If someone knows a better way to do it then please post it in the comments. BTW..thats in ruby.
I am really puzzled about something and would like to know your answer since you are here. The question is, when or under what conditions an experienced programmer cannot write a code like this
print something if some_other_thing == something_else
Considering that the guy has written codes like this thousands of times and hundreds of times involving very complex logic.
My thoughts are below, you can use the comment form for yours:
1) when the guy hasn’t understood the problem fully
2) when the guy is sleeping
3) when the guy is stressed
4) when the guy is not able to focus
5) when the guy is dumb, no i don’t think a dumb guy can become an experienced programmer
PS. I would like to expand on this post in future and write in detail about it once I thought about it fully and gathered some opinions.
PPS. I would also like to know if someone else had similar experiences / aware of stories like this in other fields as well, not necessarily in programming.
Sign up and be a part of SPhred.com and don’t forget to invite your friends ;o)
Comments : 2 Comments »
Tags : random string, ruby
Categories : Personal, Ruby On Rails






