Actually, this is a pretty non-optimal strategy. The correct strategy, which changes for each machine (which is why its a pain in the @ss, which is also why the casinos don't mind too much since they know most people won't be bothered to learn), is very non-intuitive. For example, when do go for the straight or flush? What if you have 4 to a royal, but also a pair of kings? In assuming a basic Jacks or Better machine, if you get 5 garbage cards all less than a jack, you draw 5 new cards but what if you have a J-Q-A, or a J-Q-K or a J-K-A? The strategy may call for keeping the 2 non-A cards only.
And even then, unless you hit the royal, its still a loser.
For curiosity sake, I looked into this years ago but its way too much effort for me. Even in favorable conditions, spending a 100 hrs to hit the royal may only get you $10 per hour. What a waste.
Things get a little trickier with jacks or better, but the basics are still the same. For straights only go for them if you're missing the outside cards (or preferably card), 6-7-8 is a good place to build a straight from, 6-7-8-9 is fantastic, 6-7-8-10 is no good, only go for flushes if your 4/5 of the way there. Either way if you're sitting on something that will make money (jacks or better) don't break it up. Computerized/ video poker rewards consistency and cowardice. Real life poker rewards bravery and bluffing (though you should STILL never try to draw into an inside straight).