-1

I am looking for a satisfying solution of how to generate a random number.

I looked at this, this, this and this. But am looking for something else.

Most of the posts mention using, R[n+1] = (a *R[n-1 + b) %n, this pseudo-random function, or some other mathematical functions.

But weirdly I am not looking for these; I want some non-algorithmic answer. Precisely, an "Interview" answer. Something easy to understand, not to make the interviewer feel that I mugged up a method :) .

Cœur
  • 37,241
  • 25
  • 195
  • 267
Spandan
  • 2,128
  • 5
  • 25
  • 37
  • 1
    What is a "non-algorithmic answer"? It'd be more helpful to say what you're looking for instead of listing things that you aren't looking for. – Blender Jun 06 '13 at 19:04
  • Is it language agnostic? – Lion Jun 06 '13 at 19:04
  • AFAIK the easiest way (and the "standard" way) to generate random numbers is the one you wrote up there. how are you going to generate a random number without an algorithm to cook it up? – blue Jun 06 '13 at 19:06
  • i think he means an algorithm that is not so popular? – tgkprog Jun 06 '13 at 19:06
  • 1
    [http://www.random.org/](http://www.random.org/) – GriffeyDog Jun 06 '13 at 19:09
  • I know i have asked a weird question,but thats' my requirement,a method which doesnt make the interviewer feel that i mugged somethin up,somethin trivial yet powerful.. – Spandan Jun 06 '13 at 19:09
  • 1
    Non-algorithmic? Write the numbers 1 through N on pieces of paper, throw them up in the air, and see which one lands farthest from you. – D Stanley Jun 06 '13 at 19:10
  • 1
    There are only two options: an algorithm of some kind (of which the one you point out is merely the simplest of hundreds), or hardware. Hardware includes things like specialized TRNG devices to simpler things like getting timings of mouse movements. – Lee Daniel Crocker Jun 06 '13 at 19:11
  • @Spandan: What you have listed in your question is extremely simple and works somewhat well. I would start by figuring out what you're looking for before asking a question. – Blender Jun 06 '13 at 19:11
  • obligatory http://xkcd.com/221/ – Daniel Jun 06 '13 at 19:12
  • I knew i was gonna be downvoted,but it was worth a try :) – Spandan Jun 06 '13 at 19:35

2 Answers2

1

For an interview question, a common answer might be to look at the intervals between keystrokes (ask the user to type something), disc seek times or input from a disconnected source -- that will give you thermal electrons from inside your MIC socket or whatever.

LavaRnd uses a digital camera with the lens cap on, which is a version of the last.

Some operating systems allows indirect access to some of this random input, usually through a secure random function; slower but more secure than the usual RNG.

Depending on what job the interview is for, you can talk about testing the raw data to check for entropy, and concentrating the entropy by using a cryptographic hash function like SHA-256.

There are also specialised, and expensive, hardware cards which use various quantum effects to generate true random numbers.

rossum
  • 15,344
  • 1
  • 24
  • 38
0

Take the system time, add a seed, modulo the upper limit. if upper limit is less than 0 than multiply it by -1 and then later the result subtract the max... not very strong but meets your requirement?

If you have a UI and only need a couple of randoms can ask the user to move mouse around, enter a few seeds, enter a few words and use them as seeds

tgkprog
  • 4,493
  • 4
  • 41
  • 70