Okay, I've had the same problem and clearing cache did not resolve it. After an hour of reading posts where everyone says "clear cache" I've decided to really understand whats going on. So I'll try to explain to other people like me (who just have started). Hope I'm not wrong and if so, correct me please.
I'll assume that you're following the book's tutorial, where you have Acme/DemoBundle. And accessing it from production environment gives you 404. First of all, you should have a clear understanding of what bundle in Symfony means. It's something like a plugin. It's like a puzzle. Symfony is like a big puzzle and your app is a piece of the puzzle.
So first, lets look in the AppKernel.php file in ./app. What we see there is registering bundles. Like putting the pieces of the puzzle. And first we say "okay, i want the main pieces of the puzzle, the Symfony bundles" and then we say "and if I'm in debug mode, I also want some other pieces." And there is your piece, your bundle. So that's why you can't access it from production environment. You only register the bundle from developer environment. Register your bundle (Acme/DemoBundle/AcmeDemoBundle) in the top, and you can access it from production environment.
Second, go into ./app/config/routing_dev.yml . This is the routing for development environment. We're saying "okay, I have some routing information in @AcmeDemoBundle/Resources/config/routing.yml and in development environment, our bundle is found. But look in ./app/config/routing.yml .We don't mention anything about our custom routing. It's like the Framework doesn't know about the existence of our routing file. And this is in the production environment. So adding the last part of routing_dev.yml to routing.yml (in ./app/config/) should fix the problem.
After that clear the cache and check if /app.php/random/[number] works. It should be.
I hope this will help someone like me, understanding some of the basics.