Identicon
Random icon you are talking about is an Identicon.
Identicons are icons that are generated from some form of user information.
An Identicon is a visual representation of a hash value, usually of an IP address, that serves to identify a user of a computer system as a form of avatar while protecting the users' privacy. The original Identicon was a 9-block graphic, and the representation has been extended to other graphic forms by third parties. – Wikipedia
Sample Implementation
You can have a look at:
NIdenticon - a C# library that helps creating simple Identicons. Examine
IdenticonGenerator
class that has only one method calledCreate()
. You should be able to extract the algorithm/general idea from it.Contact-Identicons source - Android app source code. The app generated Identicons. This blog post includes a sample of Java code used to generate a 5*5 pixel, horizontally symmetrical identicon much like the ones github uses.
IGIdenticon source - Objective-C identicon generator. A port of identicon library written in Java.
Good luck!