Returning a fixed number of rows should be rather easy. Use the Criteria.setFirstResult() and Criteria.setMaxResults() methods.
Sorting in random order may be a bit more complicated. The only thing I can think of is to subclass the org.hibernate.criterion.Order class and implement the toSqlString() method to return something that generates:
Code:
... order by rand()
This will of course only work if your database supports it. Take a look at the MySQL documentation for an example:
http://dev.mysql.com/doc/refman/5.0/en/ ... ction_rand