improve random process, create a function object and use it.