Directors Ron Clements and John Musker wanted so badly for Robin Williams to play the Genie that they literally wrote the role with him in mind. They even animated lines from one of his old comedy albums as if the Genie was performing them as a way to convince Williams to accept the role.
Eric Goldberg, the supervising animator for Genie, said that the character totally embodied Robin Williams. In fact, Williams took the script and made it his own, often going off-book: "We didn't expect him to come back with all the celebrity impressions the first time we recorded him, so we re-adapted. We incorporated Robin's riffs into the fabric of the film."
After Robin Williams' death in 2014, Goldberg tearfully reminisced about his relationship with Williams on the film, saying, "He was a real-life Genie, and, boy, did he grant our wishes."