Subhash Pavuskar wrote:How to Generate random number without using function ? can anyone tell me the logic ..

Did you have a look at Random Number Generation algorithms? You can use any one of them. They are just some mathematical formulations that you can implement in code.

And I think this has been asked before as well in the forum. May be SearchFirst would have helped?

@John Jai : You are using function here and i am asking about without using function call.

@Mohamed Sanaulla : I searched and they people used function ,so if you found the problem solution for the same then please let me know.

John Jai
Bartender

Joined: May 31, 2011
Posts: 1776

posted

1

Subhash Pavuskar wrote:@John Jai : You are using function here and i am asking about without using function call.

Yes - I just wanted to know your purpose. And please refer functions as methods.

Subhash Pavuskar wrote:@Mohamed Sanaulla : I searched and they people used function ,so if you found the problem solution for the same then please let me know.

If it’s an interview question, that changes everything You can remind them what the definition of a function is: for the same input, a function always generates the same result. A random number generator is different; it generates a different result each time. So it isn’t a function.
Math.random() is in fact a function; it does not actually generate random numbers, but numbers whose value is difficult to predict from their seed. You would have to take the java.util.Random class apart to find how it is done. The code is in the usual src.zip file.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39393

28

posted

0

A few minutes ago, I wrote:. . . A random number generator is different; it generates a different result each time. . . .

Imprecise!! A random number can be repeated. I once won £10 by guessing a coin. I stuck on “heads” every time and people said, “What about the law of averages?” There is no such thing as a law of averages, and I won the £10

suresh krishan wrote:random number is between 0.0 to 1.0

inclusive or exclusive?

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39393

28

posted

0

fred rosenberger wrote: . . . inclusive or exclusive?

Semi-exclusive.

That shows how precise you have to be when you work with computers. The java.util.Random#nextDouble() documentation returns a number between 0.0 and 1.0, and it tells you whether it is inclusive or exclusive.