RSS Feed for This PostCurrent Article

Why Does rnd() Keep Changing?

My friend Tom found this, I thought it was worth re-sharing:

I can think of several ways of making things like /dev/random stop changing, mainly based on what my customers have done to machines.

| Comments

Trackback URL

  1. 8 Comment(s)

  2. By Matt Simmons on Oct 6, 2008 | Reply

    Hah! That’s absolutely astounding!

    You’ve got to wonder what they thought rnd() was…

  3. By Steven Schwartz on Oct 6, 2008 | Reply

    Clearly misunderstanding the differences between generating a RANDOM, and wanting a ROUND function.

    I don’t know if .NET supports a ROUND function, oh well.

  4. By Dijutal_Phreak on Oct 6, 2008 | Reply

    I agree with you that it’s a funny thing…. But I don’t think it’s right to mock the poor person who doesn’t understand the differences between round and random. It’s obvious that the person doesn’t know what he/she is doing and at least they’re asking for legitimate help in a fairly well respected knowledge board. Everyone has to start at the level of a basic “user/developer” Maybe a posting/direct e-mail would rectify that?

  5. By MarcW on Oct 7, 2008 | Reply

    Well actually, while i cant ascertain the exact function of the program, in some cases, using a rnd() function that doesn’t change is quite usefull. (as in has a fixed series of numbers)

    Just imagine when programming a 3D enviroment, using a rnd() value for the coordinates of trees for example. using a rnd() function (thats still random, but has a fixed order) you have a very effectient way of generating the same layout of trees every time you render the scene. I’m not sure how this works in ASP.NET, but in VB6.0 the rnd() function is predictable, and great for such things. If you really need to randomize, you could use something like randomize timer (so that every minute the sequence of numbers would change).

    It was one of the first things I learned about programming using random values: rnd() is NOT random, theres always some logic in it, because it is generated by a computer that cant just “by instinct of gut feeling” pick a number.

  6. By Matt Simmons on Oct 7, 2008 | Reply

    @MarcW

    It all depends on what you seed it with

  7. By MarcW on Oct 8, 2008 | Reply

    Matt, I totally agree with that, you can seed rnd() so much that it gets to be as close to really random as is possible with a computer. I just wanted to point out that there are advantages to having a rnd() that is predictable

  8. By Bob Plankers on Oct 8, 2008 | Reply

    Um, if you need a predictable rnd() just write your own:

    int rnd() {
    return 1;
    }

  9. By Bob Plankers on Oct 8, 2008 | Reply

    @Dijutal, I think it’s perfectly fine to give this person a little bit of a hard time since they could have just looked it up in the online function reference. In this era of Google & total searchability a simple search should have tipped them off.

Post a Comment

 

Please note that while in principle I don't mind promotion of a non-personal web site or blog in the fields below, any comments that are off-topic, derogatory, or spam-like will likely be removed at my discretion.