Always sand in the direction of the wood grain to minimize visible scratches showing through a stain or finish. An exception commonly occurs when sanding woodturnings because of the difficulty sanding with the grain. To compensate and still eliminate visible scratches, sand to a much finer grit (usually 400 or 600 grit).
You can also sand across the grain using a random-orbit sander as long as you don’t move the sander rapidly over the surface. Best practice is to follow the random-orbit sander with at least one hand sanding in the direction of the grain using the finest grit you used with the sander. Do this to eliminate “squigglies,” or small circular scratches left by the sander.