How to generate images for profile picture in Drupal 7?
I could achieve that by the Identicon module.

This module generates and displays identicon images in place of the user picture for users who do not have a picture.
The generated identicons are pixel style images. The number of pixel blocks that the images contain can be configured. You can choose whether the generation is based on the user's email address or the user id. If the generation is email-based, users will get a new image if they change their email address. On the other hand, they get the same image even if they cancel their account, and register again using the same email. If the generation is user id based, changing the email address will not change the identicon, but if the user account is cancelled, the user will not get the same image when they re-register.

Checkout the similar modules Gravatar and User Pic Kit