>I want to know what is the logic used for generating a random number.
There's logic to generating random numbers? :p
>Can anyone tell me the algorithm for random number generation without using standard library functions?
There are a lot of algorithms for random number generation that vary from simplistic and crappy to opaque and excellent. You can have statistically random generators such as linear congruential generators (rand is almost always an LCG) or the vanilla mersenne twister, or cryptographically secure random generators like Blum Blum Shub. What you need it for is very important, but most likely you're just looking for a decent LCG. Rashakil Fol posted my recommendation for a good introduction. ;)