1

Suppose you generate random numbers using the seed as the time elapsed in seconds since january 1970 as in microsoft library. But you change the seed after every single random number generated. Will that give a truly random result. Why or why not?

Edit I just had one more part to the question. What if I get the seed to be non-deterministic. For a small example, take that the seed is generated by an already existing TRNG(true random number generator). In other words, if I can make the seed non deterministic somehow, will I be able to generate a random sequence i.e. a non - deterministic sequence. Why or why not?

rahulgarg12342
  • 155
  • 1
  • 10
  • Note that someone or something might run your program multiple times per second (`Gah, need some GUIDs right now, pah pah pah`), in which case your program might deliver undesired results. – Sebastian Mach Apr 15 '14 at 12:05
  • 1
    Do you mean something like http://www-cs-faculty.stanford.edu/~uno/news02.html#rng? If so, it depends, but since even Knuth botched that one, I'd guess probably not :) – loreb Apr 15 '14 at 13:59
  • No. You will in essence be producing a sequence of numbers which are a hash function of the time, which may appear random, but which will be quite predictable. – Lee Daniel Crocker Apr 15 '14 at 17:46
  • Related: see http://stackoverflow.com/questions/13779441/resetting-pseudo-random-number-generator-seed-multiple-times – fearless_fool Apr 16 '14 at 18:36

2 Answers2

2

Essentially, your technique simply shifts the "randomness" to when you call the random() function: if you call the function at deterministic times (e.g. once per second) the results will be deterministic. If you call the function at random times, the results will be random.

More accurately, it depends on the what value you call the seed() function with. If you call seed() with deterministic values, the results of the subsequent call to random() will be deterministic.

update (by request):

A software random generator is COMPLETELY deterministic; the sequence of values it produces is exactly determined by what you pass to the initial call to seed(). As a result, if you call seed() with a known value, then you can predict exactly what series of values you'll get from subsequent calls to random(). If you call seed() with a truly random number, then calls to random() will be correspondingly random.

(But that begs the question: if you have random number to pass to seed(), why bother calling random() at all?)

fearless_fool
  • 33,645
  • 23
  • 135
  • 217
  • @rahulgarg12342: certainly: if your seed is non-deterministic, the result of seed(); random() will be non-deterministic (e.g. random). I'll expand on my answer above... – fearless_fool Apr 16 '14 at 14:57
  • I need to call random to generate more random numbers from one single random number. I was thinking of generating a random sequence from a truly random seed using Mersenne Twister though I do not even understand the math behind mersenne twister. But anyways If that approach of mine is wrong please tell me. Thanks :). – rahulgarg12342 Apr 16 '14 at 15:13
  • But what will you seed the Mersenne Twister with? Regardless of the PRNG algorithm -- Mersenne Twister or others -- if you seed it with a known value, you'll get a known sequence of values every time you run it. That's why using the low order bits of a nanosecond timer, or decay particles from a radioactive source, or bits from some web cam, can make good seeds. In short, if your seed ain't random, it doesn't matter how good your PRNG is; the results won't be random. – fearless_fool Apr 16 '14 at 17:37
  • I got it but I have a method of generating completely random seeds which you will at the moment think is not possible using a computer. It will take some time to develop but once its done, I will tell you about it in a week's time. The only problem I will have is that the seed will be completely random but it certainly won't be very big. It will be from around 1 - 100000000. – rahulgarg12342 Apr 17 '14 at 03:02
  • Please tell me if my method is right if somehow I manage to get a random seed but within a limit. But @kendall is disagreeing with this. Please help and clarify. – rahulgarg12342 Apr 17 '14 at 16:39
  • So: if you have a source of truly random numbers (that is, NOT generated by a PRNG on a computer, but something like looking at radioactive decays), you CAN use them as seeds to a PRNG. The catch is that SOME PRNGs, including many implementations of the Mersenne Twister, take a while to get "really random" after being seeded. Check out wikipedia for details. And please read and understand http://stackoverflow.com/questions/13779441/resetting-pseudo-random-number-generator-seed-multiple-times. I look forward to details on your TRNG! – fearless_fool Apr 17 '14 at 23:08
  • Yeah Sure but I have to work on it but once my proposal is accepted its just a piece of cake. Now I cannot tell which proposal but the seeds will be truly random. And every time a user makes a new request to generate a sequence of random numbers, a new seed will be provided to the Mersenne Twister. Please tell me if this is fine. Just give me your email as well if you can so we can discuss later on. – rahulgarg12342 Apr 18 '14 at 07:17
  • @rahulgarg12342: "Tell me if this is fine." Without knowing your TRNG and how you'll drive the PRNG with it, I can only say possibly yes for statistically independent numbers, and absolutely not for cryptographically secure numbers. See http://stackoverflow.com/a/13807851/558639 for an explanation. – fearless_fool Apr 19 '14 at 02:49
  • can you please provide me with an easy explanation for that. What do you mean by statistically independent numbers. But for sure I know that the numbers cannot be guessed. – rahulgarg12342 Apr 19 '14 at 06:20
  • Please also give me your email or send it to me on rahulgarg12342@gmail.com so I can discuss my idea with you. For further clarification, the numbers i will use a the seed will be such that nobody can guess them but they will have a limit and not be very large. – rahulgarg12342 Apr 19 '14 at 07:35
  • please reply to your email. Thanks. – rahulgarg12342 Apr 21 '14 at 09:47
  • Please check your mail. Thanks. Also do tell me if you check your mail frequently so that I will not post any further comments on this website to tell you that I have given a reply. I just do this because I feel that you use this website more frequently and do not need to check your mail. – rahulgarg12342 Apr 21 '14 at 15:06
1

True randomness does not require a seed. Seeding is only applicable to PRNGs, which are 100% deterministic, and not truly random.

So no, using a PRNG in any form will not yield true randomness.

Kendall Frey
  • 43,130
  • 20
  • 110
  • 148
  • but if you do not know the seed, then the results will be random, wont they? In short if the seed is unknown and completely random, then the sequence for you will be random. – rahulgarg12342 Apr 17 '14 at 03:04
  • @rahulgarg12342 This actually isn't true. I noticed once with my calculator that if I generated a sequence of random numbers, the last digit repeated every 7 numbers, and was completely predictable. I couldn't predict the rest of the digits, but one of them was predictable with just my brain. It was obviously not random, even though I didn't know anything about the internal state. – Kendall Frey Apr 17 '14 at 11:40
  • Do you mean the last number or the last digit? But even with randomness, there is nothing like that the number can never be repeated seven times. Do you agree. Random could also be like a number being repeated 10 times. Please explain what do you mean? thanks. – rahulgarg12342 Apr 17 '14 at 16:38