Wild Magic Rules
Wild surges are fluctuations in a spell caused by randomization or chaos in the source of the spell energy. These randomizations can make the spell weaker or stronger, or even cause it to have a totally different effect or backfire upon the caster.
When a spellcaster casts a spell with a wild surge, the player rolls 4d6, disregards the lowest number, and compares the result to Table 1-1: Ability Modifers and Bonus Spells in the Player's Handbook.). The result is the surge modifier. The surge modifier is added to the caster level of the spell. A spell's caster level cannot be modified below 1, although the caster level can be modified below the minimum level to cast a spell. If the modified caster level means that the spell's range cannot reach the target, the spell activates at the end point of the spell's new maximum range along the line of effect to the original target. A spell with a caster level of 0 or less does not function (as if the spellcasting had been disrupted).
Example: Marlee at 5th level spends a wild magic point to cause a wild surge in her fireball spell. She rolls 4d6 and gets 1, 1, 1, 4. Disregarding the lowest die gets her a 6, which according to Table 1-1: Ability Modifers and Bonus Spells gives her a surge modifier of -2. Adding the surge modifier to her caster level gets her a final caster level of 3 (5 + -2). Her fireball acts as if cast by a 3rd-level caster (it has a 520 ft. range and deals 3d6 fire damage).
If the surge modifier is an even number, the spell may have a greater surge. The caster attempts a Will saving throw (DC 15 + spell level). Like all saving throws, the caster can voluntarily fail this saving throw. If failed, there is no greater surge. If successful, the caster rolls d% and consults the Wild Magic Greater Surge Table below. Higher results are generally more beneficial to the caster, lower results are generally less beneficial. All greater surge effects based on spells take effect at the caster's normal caster level. Any surge effect that is inappropriate for the spell (such as "Spell changes energy type" for a spell that doesn't do energy damage) means the greater surge has no effect.
Greater Surge Table