First the reference from the [scripture](http://www.sacred-texts.com/hin/m11/m11024.htm):

> "Gandhari said ... Since deliberately, O slayer of Madhu, thou wert
> indifferent to this universal carnage, therefore, O mighty-armed one,
> thou shouldst reap the fruit of this act. By the little merit I have
> acquired through waiting dutifully on my husband, by that merit so
> difficult to attain, I shall **curse thee**, O wielder of the discus and
> the mace! Since thou wert indifferent to the Kurus and the Pandavas
> whilst they slew each other, therefore, O Govinda, thou shalt be the
> slayer of thy own kinsmen! **In the thirty-sixth year from this, O
> slayer of Madhu, thou shalt, after causing the slaughter of thy
> kinsmen and friends and sons, perish by disgusting means in the
> wilderness.** The ladies of thy race, deprived of sons, kinsmen, and
> friends, shall weep and cry even as these ladies of the Bharata
> race!’"

Now to understand the magic number, first we have to rationally understand what is a "curse" (or a "blessing")?

The curse is not something regular "bad-mouthing" or "trash-talking" we see in today's society or media where people give to each other. Those are just their frustration or anger being short sighted people.

**A Curse (*Shraap*) or a Blessing (*Aashirwad*) in its true sense is a "Definite Prophecy".**

The course of events of past, present, future are innumerable interactions of 3 modes of material nature in innumerable forms. Some even say it is pre-decided:  
[Is our destiny pre determined? If yes, then why do our actions affect our karma?](http://hinduism.stackexchange.com/q/2399/1049)

In any case the to-be events of future are not just random. They can be prophesied. Such "spiritual capability" of issuing genuine curse (or blessing) can come by various means:

 - Having a strong knowledge of subtle activities of *Karma* through
   experience or enlightenment
 - Having gone through sever austerities and observing own *Dharma*,
   with utmost perfection
 - Being in true feat of rage or happiness, certain doors of mind are
   opened for a short while which helps predicting future (relevant today)
 - Natural power acquired from the deeds of past births
 - ... 

We may count Gandhari in the 2nd league. She had observed her *Stree Dharma* with utmost perfection throughout her married life and hence she had certain blessings from various elders like Bhisma, Vyasa. Refer [this excerpt](http://www.sacred-texts.com/hin/m11/m11015.htm):

> Devoted to her lord, that highly blessed lady had always practised
> high vows. Undergoing the severest penances, she was always truthful
> in her speech. In consequence of the gift of the boon by the great
> rishi Vyasa of sanctified deeds, **she became possessed of spiritual
> knowledge and power.**

Gandhari was well aware that Duryodhana was foolish and never obedient to elders. The Paandavas were so much essential to be saved & unharmed. But as an emotional mother of all the slain sons, she also was in feat of rage towards Vaasudev Krishna, who in her opinion could have saved this war.  
Due to increasing power, Yaadavas too were on the same path of self-destruction like Kurus and other kings were during Mahabharata war.  
*With her spiritual power of foreseeing the future along with anger of a mother she predicted something which was supposed to happen in 36 years.* 

Ofcourse, Krishna too wanted it to happen and he accepted it whole-heartedly. Though Gandhari cursed for Krishna being the reason of killing his kinsmen, Krishna actually was not the direct reason for that. Instead he chosen them to kill each other. Now we can interpret it to be "alteration" or "correction", it's up to us. **In nutshell, "36 years" was not a "chosen" figure, rather a "destined" figure.**

> Hearing these words, the high-souled Vasudeva, addressing the
> venerable Gandhari, said unto her these words, with a faint smile,
> ‘There is none in the world, save myself, that is capable of
> exterminating the Vrishnis. I know this well. I am endeavouring to
> bring it about. In uttering this curse, O thou of excellent vows, thou
> hast aided me in the accomplishment of that task. The Vrishnis are
> incapable of being slain by others, be they human beings or gods or
> Danavas. **The Yadavas, therefore shall fall by one another’s hand.’**

Here is the [advice of Sage Vyasa](http://www.sacred-texts.com/hin/m11/m11013.htm) which shows his trust in the words or prophecy of Gandhari:

> The rishi, addressing his daughter-in-law at the proper moment, said,
> ‘Do not avail thyself of this opportunity for denouncing a curse. On
> the other hand, utilize it for showing thy forgiveness. Thou shouldst
> not be angry with the Pandavas, O Gandhari! Set thy heart on peace.
> Restrain the words that are about to fall from thy lips. Listen to my
> advice. Thy son, desirous of victory, had besought thee every day for
> the eighteen days that battle lasted, saying, "O mother, bless me who
> am fighting with my foes." Implored every day in these words by thy
> son desirous of victory, the answer thou always gavest him was,
> "Thither is victory where righteousness is!" **I do not, O Gandhari,
> remember that any words spoken by thee have become false.** Those words,
> therefore, that thou, implored by Duryodhana, saidst unto him, could
> not be false.