i have one table "documents" and i want to fetch 6 records randomly is
there any solution reply me
Yes, clearly there *is* a solution.
However your question fails to be "smart" on a number of counts. By omitting critical details (e.g. what sort of table? in a database or an array? what sort of database?) then nobody can give you a specific answer. Also, you haven't given any indication of which avenues you've already explored, or indeed of having made any effort at all on your own behalf to try to solve the problem before posting. Maybe you have, but the important thing is you haven't *shown* that you have. So why do you expect someone on the list to take more effort in replying than you did yourself in posting?
To illustrate this, let me try making up a question or two which you could have asked instead. These may or may not be anything like the actual problem you have.
"I have a table 'documents' stored in a MySQL database that I'm accessing using ActiveRecord. I'd like to be able to pick 6 rows from that table at random. I can read all the rows into an array using Document.find(:all), but I haven't been able to find a function in Ruby to pick a random element. Could someone suggest where I should look? Thanks, Pragash"
In this case, someone might point you to the Kernel#rand method, and/or to the many Ruby documentation sources.
However, your problem could be completely different:
"I have a table 'documents' stored in a MySQL database that I'm accessing using ActiveRecord. I'd like to be able to pick 6 rows from that table at random. I thought about reading the entire table into an array using Document.find(:all), and then using rand(N) to pick elements from it, but unfortunately the table has over 1 million rows and is too large to be read into RAM. There are many gaps in the 'id' sequence column, so I can't do Document.find(rand(N)+1) either.
Could someone suggest an efficient way to do this? Thanks, Pragash"
This question is completely different. It's not about Ruby but about MySQL, since really you want to know if there's a SQL statement which can ask MySQL to retrieve rows at random. You may find someone on this list who knows the answer, or you may be referred to a MySQL mailing list.
To get more chance of a useful response you should also post relevant details of your environment (which operating system and version; which versions of Ruby, MySQL and ActiveRecord you're using), samples of code you've run, and the errors you got back, copied and pasted verbatim.
The following document gives lots of really good, practical advice on asking questions to a mailing list in a way which elicits the most useful response:
http://www.catb.org/~esr/faqs/smart-questions.html
I strongly suggest you read it.
Regards,
Brian.