How did every teenager in America magically understand that "Austin Powers: The Spy Who Shagged Me" was the movie to go see last weekend?

Why, for that matter, did my own teenage daughter attend this appalling film twice over the weekend -- memorizing half the dialogue so that she could regale the family with tales of Austin, his nemesis Dr. Evil and a sadistic dwarf named Mini-Me?

Whatever mysterious process was at work, it has already made Austin Powers a monster hit. The opening weekend's gross at the box office was $57.2 million, including Thursday night previews. That's huge, even by Hollywood blockbuster standards -- especially for a sequel to a low-budget movie about a randy spy with bad teeth who, as the whole world knows by now, likes to say: "Oh, behave!"

A consultant named Winslow Farrell at PricewaterhouseCoopers is trying to make a science out of explaining this chaotic process. Using the mathematical tools of "complexity" developed at the Santa Fe Institute, he has come up with simulations that allow you to understand how advertising and word of mouth combine to produce the "buzz" that, in turn, produces a hit.

With Farrell's models, you can literally watch that cascade of interest move across a computer screen like a summer storm, as a thousand simulated consumer "agents" pass along the word-of-mouth recommendations that lead to purchases.

The success of the Austin Powers sequel wasn't any surprise to Farrell, for example. His methods would predict a huge opening weekend for the film, because it would ride on a crest of devoted fans -- kids like my daughter -- who, by repeating their favorite lines, become part of the marketing process.

"It's an example of shock-wave marketing," Farrell explained in an interview at his office in New York this week. Several weeks before the movie opened, billboards and newspaper ads began appearing with trademark Austin Powers lines. "Five times a day? Yeah, baby!" announced billboards touting Virgin Atlantic Airways' flights to London. "Milk . . . keep[s] my mojo working overtime. Oh, behave!" leered a magazine ad, with Austin drinking milk from a martini glass. There were even stories about New Line Cinema's $40 million promotional campaign, including one in Monday's New York Times.

Farrell has outlined his marketing theories in a new book called "How Hits Happen: Forecasting Predictability in a Chaotic Marketplace." In essence, he regards markets as complex systems that operate "on the edge of chaos and order." Rather than displaying the smooth, continuous functions described in traditional economics texts, real markets are volatile and unstable. In these real markets, small changes can produce radically different outcomes.

Farrell and his associate, Bernhard Borges, showed me a computer simulation they did for a major U.S. record company several years ago. This is the one where you can actually watch a hit sweep across the screen.

In the pop-music simulation, Farrell and his colleagues created 1,000 detailed computer profiles, known as "agents," which approximate the demographics of the rock-music market. Each of these agents has different tastes and interests, and a number of friends to whom they recommend music. Agent 509, for example, is friends with 17 other agents, each of which has a different level of trust in Agent 509's musical taste.

So we instruct the computer to simulate how the market reacted in 1995 to the first CD released by Hootie and the Blowfish. Each of the thousand agents is represented on the computer screen by a tiny rectangle, which gets redder as the agent becomes more interested in a particular CD and finally gets a little blue dot in the middle, if the agent decides to buy the CD.

Waves of pink move across the screen, as interest in the band develops among college kids; the waves deepen to scarlet as the simulated consumers tell their friends, and blue dots begin to appear. There's an odd fall-off, and then sudden new waves of crimson and a sea of blue dots -- as the Hootie CD becomes a mega-hit. What accounted for that fall-off in the middle of the simulation? College vacation, of course.

Another example of Farrell's technique is a simulation he built for Macy's of its store at the Aventura Mall in Miami. It's a 3-D model of the store, with little robot-customers moving about the place. These agents have been programmed with data from real customers -- what they buy, how long they spend in the store. As they move along the aisles, they smile when they see something they might buy, and frown when they don't.

Farrell hopes the model will help Macy's design its stores better, with fewer bottlenecks, better display and more efficient staffing. But there's something mesmerizing about just watching these little guys go shopping!

Farrell's models are still in their infancy, but they're a sign of what lies ahead as marketers begin to embrace new technology. As programmed and pre-packaged as this future might seem, the delightful fact is that it's forever vulnerable to real people and their tastes -- to the sudden, break-out hit that nobody heard of the day before yesterday but everybody wants to see today.