Question: I want to generate random numbers manually. I know that every language have the rand or random function, but I'm curious to know how this is working.
Does anyone have code for that?

Answer: 
Have a look at the following:

[Random Number Generation](http://en.wikipedia.org/wiki/Random_number_generator)

[Linear Congruential Generator](http://en.wikipedia.org/wiki/Linear_congruential_generator) - a popular approach also used in Java 

[List of Random Number Generators](http://en.wikipedia.org/wiki/List_of_random_number_generators)

And here's another [link](http://www.javamex.com/tutorials/random_numbers/java_util_random_algorithm.shtml) which elaborates on the use of LCG in Java's Random class
If you are wanting to manually, hard code, your own random generator I can't give you efficiency, however, I can give you reliability. I actually decided to write some code using time to test a computer's processing speed by counting in time and that turned into me writing my own random number generator using the counting algorithm for modulo (the count is random). Please, try it for yourselves and test on number distributions within a large test-set. By the way, this is written in python.

```
def count_in_time(n):
   import time
   count = 0
   start_time = time.clock()
   end_time = start_time + n
   while start_time < end_time:
       count += 1
       start_time += (time.clock() - start_time)
   return count

def generate_random(time_to_count, range_nums, rand_lst_size):
    randoms = []
    iterables = range(range_nums)
    count = 0
    for i in range(rand_lst_size):
        count += count_in_time(time_to_count)
        randoms.append(iterables[count%len(iterables)])
    return randoms

```