If the table is on the big side you want to avoid using count(*) as it is a sequential scan in most databases.
In a real database you can create a seperate table to hold the count value and create a trigger that updates that value on inserts/deletes and such, then select from there.
On the other hand, using the rand() function in a sql query on a large table is also very slow, so it might still be much faster to run a select count(*) query first anyway.
On Postgresql, due to its MVCC nature, count(*) is as slow as any other flavor of aggregate, i.e. not optimized for the simple case with no where clause.
If the rows are <10,000 a select count(*) should be plenty fast by itself.