• (cs) in reply to Mung Kee

    Mung Kee:
    chb:
    The naming of the variables kills me.
    (a|an|the|its)

    Maybe she's a "hungarian notation fundamentalist" *ducks*


    I was going to jokingly make this comment, but figured I'd better not after yesterdays post.

    <FONT face="Courier New" size=2>but it's not hungarian notation.  it's just mildly retarded glitter.  i'd bet the potato farm she's into boudoir photography.  it tends to attract people with low self-esteem and texas residents.</FONT><FONT face="Courier New" size=2>

    Lite: Hey Oly. You're wife's hanging all over Otto.
    Oly: Yeah. Like flies on shit<FONT color=#003060> (spit)</FONT>.</FONT>

  • (cs)

    This is not a random number generator, only an extremely bad wrapper around the already existing RNG rand().


    The following would be a real RNG:

      static int seed=1;
      double myRand(double minValue, double maxValue) {
        seed = (seed * 75) % 65537;
        return minValue+(maxValue-minValue)*(seed-1.0)/65536.0;
      }
    }
    
  • (cs) in reply to ammoQ
    ammoQ:
    This is not a random number generator, only an extremely bad wrapper around the already existing RNG rand().


    The following would be a real RNG:
      static int seed=1;
    double myRand(double minValue, double maxValue) {
    seed = (seed * 75) % 65537;
    return minValue+(maxValue-minValue)*(seed-1.0)/65536.0;
    }
    }


    Personally, I'd just return .9*maxValue. As long as the code isn't open source, nobody has anyway of proving that the number is not, in fact, random. It could run for years without actually breaking the law of large numbers. I'd be wary of a routine that produced a different number every single time -- how random is that?
  • (cs) in reply to Robert
    Anonymous:

     > year or so after she left

    Women and Computer Science don't mix! ;-)

     

    After all the half-naked chicks wallpapers I've seen on co-workers screens, I wonder [:D]

  • Elyscape (unregistered) in reply to Mike R
    Mike R:
    md2perpe:

    I think so too. I agree that she's not the "Genius" she thinks she is. She merely seems to be an average programmer, doing most things right, failing (getting a blackout?) now-and-then. Most WTF postings here are definitely true WTF:s, making you ask: "How could he/she even get the idea of doing that?"


    Are you kidding??


    This is far below what an average programmer would produce. Then again what is average? The pure lack of insight into this random number generator is unbelievable. If this were done by an average programmer, then they surely wouldn't have coughed up a hairball of a routine like this to get a random number from x to y.


    I don't know if this sort of code could even be made by an average or subaverage programmer. In an odd way, you have to be really good at it in order to be that bad, no?

  • Santa (unregistered) in reply to res2
    res2:
    itsSeed also appears to be a global... shame shame!

    No, it's a class variable. She refers to it as this->itsSeed on the next line.
  • John (unregistered) in reply to Xepol

    "You know, it might be time to make a serious effort to start getting "Brillant" entered in the wikis out there"

    I'm all for it. And we can use the WTF post about Paula as the reference for its origin.

    So, where do we start? What are wikipedia's submission guidelines? What about sending it to computer jargon/terminology dictionaries? (or, even, websters online?)

  • (cs) in reply to John
    Anonymous:
    "You know, it might be time to make a serious effort to start getting "Brillant" entered in the wikis out there" I'm all for it. And we can use the WTF post about Paula as the reference for its origin. So, where do we start? What are wikipedia's submission guidelines? What about sending it to computer jargon/terminology dictionaries? (or, even, websters online?)

    Brillant idea!

    Wikipedia is a free-for-all.  Just go to the site and start typing.

    The submission rules for the Jargon File are here: http://www.eps.mcgill.ca/jargon/jargon.html#Format%20for%20New%20Entries\

    A search with Google for computer jargon dictionaries gives a slew of sites; some of which are very serious looking and others are lighter in tone.
  • (cs)

    Alex, I'm sending you my dry cleaning bill.  My shirt got all ruined when my eyes started bleeding.  Bastard!

  • (cs) in reply to Sean
    Sean:
    At least it's pretty well-commented.


    That's like looking at a horrific traffic accident in which everyone in the vehicle died a terrible death and commenting, "Well, at least they were all wearing their seatbelts and the airbags deployed."

    [:)]
  • (cs) in reply to Stan Rogers
    Stan Rogers:
    ammoQ:
    This is not a random number generator, only an extremely bad wrapper around the already existing RNG rand().


    The following would be a real RNG:
      static int seed=1;
    double myRand(double minValue, double maxValue) {
    seed = (seed * 75) % 65537;
    return minValue+(maxValue-minValue)*(seed-1.0)/65536.0;
    }
    }


    Personally, I'd just return .9*maxValue. As long as the code isn't open source, nobody has anyway of proving that the number is not, in fact, random. It could run for years without actually breaking the law of large numbers. I'd be wary of a routine that produced a different number every single time -- how random is that?


    Too easy. 0.9*maxValue could be actually smaller than minValue. At least you should return minValue+(maxValue-minValue)*0.9
  • (cs) in reply to ammoQ

    ammoQ:
    Too easy. 0.9*maxValue could be actually smaller than minValue.

    Or larger (negative numbers)

    ammoQ:
    At least you should return minValue+(maxValue-minValue)*0.9

    This always works

    If you have a random number generator that returns results in the interval [ 0, 1 ], then your formula is a general way to return a result in the interval [ minValue, maxValue ]

    float random_A_B(float A, float B) {

       return A + (B - A) * random_0_1();

    }

    or equivalently

    float random_A_B(float A, float B) {

       float lambda = random_0_1();

       return lambda * A + (1 - lambda) * B;

    }

  • (cs) in reply to Maurits

    Note that it doesn't particularly matter whether A > B, A < B, or even A = B.

  • (cs) in reply to ammoQ
    ammoQ:
    This is not a random number generator, only an extremely bad wrapper around the already existing RNG rand().


    The following would be a real RNG:
      static int seed=1;
      double myRand(double minValue, double maxValue) {
        seed = (seed * 75) % 65537;
        return minValue+(maxValue-minValue)*(seed-1.0)/65536.0;
      }
    }
    

    Actually, your generator here has a LOT less entropy than the rand function, which at least is seeded from the system timer when it ran, which, at least, is a truely random event. Reseeding on occasion can further increase entropy. Your solution is just a complicated, but FIXED series - it always starts with the same value and always follows the same path.

    Why do people feel the need to reinvent the wheel?? The end results inevitably seem to be a square.

  • (cs) in reply to Xepol
    Xepol:
    ammoQ:
    This is not a random number generator, only an extremely bad wrapper around the already existing RNG rand().


    The following would be a real RNG:
      static int seed=1;
    double myRand(double minValue, double maxValue) {
    seed = (seed * 75) % 65537;
    return minValue+(maxValue-minValue)*(seed-1.0)/65536.0;
    }
    }
    Actually, your generator here has a LOT less entropy than the rand function, which at least is seeded from the system timer when it ran, which, at least, is a truely random event. Reseeding on occasion can further increase entropy. Your solution is just a complicated, but FIXED series - it always starts with the same value and always follows the same path. Why do people feel the need to reinvent the wheel?? The end results inevitably seem to be a square.


    For the sake of shortness, I left out the seeding from the system timer, but I guess you could easily add that ;-) Anyway, it's not meant to replace the probably much better rand(), just an illustratory example. Sidenote: The algorithm was taken from the ZX81 home computer, which is nearly 25 years old. So it's an old wheel, reinvented. Why do you think it's complicated?
  • (cs) in reply to Robert
    Anonymous:

     > year or so after she left

    Women and Computer Science don't mix! ;-)


    The world's first programmer: http://en.wikipedia.org/wiki/Ada_Lovelace

    This does not apply to Linux only:
    http://www.linux.org/docs/ldp/howto/Encourage-Women-Linux-HOWTO/x168.html#AEN171
  • (cs) in reply to Mike R
    Mike R:
    Are you kidding??

    No. I really don't think that this has the same level of WTF:ness as most other postings, where it should have been obvious to the programmer that there must be some better way. At first sight this function looks okey, although it actually is not.

    Also, I don't think that most programmers are aware of the problems with floating point numbers; usually you don't need to care. Even Intel didn't get it right...

  • (cs) in reply to triso

    "Brillant idea!

    Wikipedia is a free-for-all. Just go to the site and start typing.

    The submission rules for the Jargon File are here: http://www.eps.mcgill.ca/jargon/jargon.html#Format%20for%20New%20Entries\

    A search with Google for computer jargon dictionaries gives a slew of sites; some of which are very serious looking and others are lighter in tone."

    Right, but I make no claim to being a genius, or "Brillant". No, in fact, since I appear to care enough to come up with the idea, I must just be lazy.

    Since you've already invested all that effort into tracking down the appropriate WIKIs, would you mind just poping over there and making a few entries? That would be great, thanks.

  • azaris (unregistered) in reply to brazzy
    brazzy:
    munificent:

    I've never written an RNG myself, but I can't imagine you could do a decent one in just a few lines of code.


    Depends on what you consider "decent". Obviously it's quite easy to do a lot better than this, but getting the numbers really random (or rather, pseudo-random) without a possibility of short periods or uneven distribution of randomness between bits, is quite difficult.


    For the few serious cases where you need a (P)RNG, inventing one yourself qualifies as a definite WTF. There are just too many good examples to be found in literature.
  • (cs) in reply to John
    Anonymous:
    "You know, it might be time to make a serious effort to start getting "Brillant" entered in the wikis out there" I'm all for it. And we can use the WTF post about Paula as the reference for its origin. So, where do we start? What are wikipedia's submission guidelines? What about sending it to computer jargon/terminology dictionaries? (or, even, websters online?)


    Hum... If her real name is Paula Bean, I would suggest we anonymize it, just in case, to avoid any, hum, legal entanglements.

        -dZ.
  • (cs) in reply to ammoQ
    ammoQ:
    This is not a random number generator, only an extremely bad wrapper around the already existing RNG rand().


    The following would be a real RNG:
      static int seed=1;
    double myRand(double minValue, double maxValue) {
    seed = (seed * 75) % 65537;
    return minValue+(maxValue-minValue)*(seed-1.0)/65536.0;
    }
    }


    No, it's a pseudo-random number generator.
  • (cs) in reply to triso
    triso:

    Brillant idea!

    Wikipedia is a free-for-all.  Just go to the site and start typing.

    The submission rules for the Jargon File are here: http://www.eps.mcgill.ca/jargon/jargon.html#Format%20for%20New%20Entries\

    A search with Google for computer jargon dictionaries gives a slew of sites; some of which are very serious looking and others are lighter in tone.


    Much as I would like it, I don't think it's gonna work. It's just an in-joke, doesn't have what it takes to be a meme. It requires too much context and knowledge to be understandable and funny.
  • (cs) in reply to John
    Anonymous:
    "You know, it might be time to make a serious effort to start getting "Brillant" entered in the wikis out there" I'm all for it. And we can use the WTF post about Paula as the reference for its origin. So, where do we start? What are wikipedia's submission guidelines? What about sending it to computer jargon/terminology dictionaries? (or, even, websters online?)


    I took the liberty of adding an entry into Wikipedia:

        http://en.wikipedia.org/wiki/Brillant

    As any other Wiki, it can be modified and updated at will by anybody.  Enjoy! :)

        -dZ.
     
  • T (unregistered) in reply to md2perpe
    md2perpe:
    Mike R:
    Are you kidding??

    No. I really don't think that this has the same level of WTF:ness as most other postings, where it should have been obvious to the programmer that there must be some better way. At first sight this function looks okey, although it actually is not.

    Also, I don't think that most programmers are aware of the problems with floating point numbers; usually you don't need to care. Even Intel didn't get it right...



    Since it doesn't even return a valid pseudo-random number, I definitely think it's a WTF.

    T

  • Steve Cohen (unregistered) in reply to database guy
    Anonymous:
    Thank you, I don't know why people are so terrified of a using little arithmetic now and then.


    Because 99 times out of 100 when we do not fully appreciate the complexity of the arithmetic we get it wrong.  I do not write "random" number generators nor do I trust the ones that come with libraries.  When I need a "random" number I pull Knuth down off the shelf and find the appropriate chapter and proceed.  And for that matter, I also appreciate that anything generated purely of algorithmic information is not random, but rather pseudo-random.  If you want random, you have to involve nature (keystroke timing, network packet arrival times, reverse diode junction noise, atomic decay, etc.).

    As long as I am flaming, please do not generate your own secure hash/checksum or cryptography algorithms, unless you really know what you are doing.  And you probably don't.

  • (cs) in reply to T
    Anonymous:
    Since it doesn't even return a valid pseudo-random number, I definitely think it's a WTF.

    I haven't said that it isn't a WTF.

  • R. Armiento (unregistered) in reply to md2perpe

    This truely is a random function!, when run, it does something completely random; it either crash (divide by 0), infinite loops, or generate some output number that isn't even randomly distributed.

    The only WTF is that the function should have been called
      "theDoRandomAction"
    to confirm with the naming scheme of the code.

    Here is a suggested use for it (pseudocode):
      [do something -> it goes wrong]
      [try to recover -> failure]
      [try to gracefully exit -> fundamental failure]
      [try to crash, burn, and fall over -> tragic failure]
      // well, lets hope and pray this fixes it
      theDoRandomAction(1,10)
     
    :)

  • curious (unregistered) in reply to aikimark
    aikimark:

    It seems to me that anytime the range is mostly negative, the routine will enter an endless loop condition.

    Example: <FONT face="Courier New">theMin := -15  theMax:=0</FONT>

    Also, it might just SEEM like an endless loop if <FONT face="Courier New">theMin</FONT> is a very large number, such as 3.1E31

    (this is my first WTF post -- thanks to Dennis Sherman for telling me about this site)

     

    Let's do the math with this.

    Range = 0 - -15

    Range = 15

    Next the for loop:

    for (; 15 <= aValue; aValue -=15)

    it still decrements aValue so eventually aValue will be less than 15

     

     

  • (cs) in reply to curious
    Anonymous:
    aikimark:

    It seems to me that anytime the range is mostly negative, the routine will enter an endless loop condition.

    Example: <font face="Courier New">theMin := -15  theMax:=0</font>

    Also, it might just SEEM like an endless loop if <font face="Courier New">theMin</font> is a very large number, such as 3.1E31

    (this is my first WTF post -- thanks to Dennis Sherman for telling me about this site)

     

    Let's do the math with this.

    Range = 0 - -15

    Range = 15

    Next the for loop:

    for (; 15 <= aValue; aValue -=15)

    it still decrements aValue so eventually aValue will be less than 15

     

     



    range cannot be negativ, look at the first lines:

      if (theMin >= theMax) {
    // error in parameters, so return 0.0
    return 0.0;
    }


  • (cs) in reply to munificent

    As for "I've never written an RNG myself, but I can't imagine you could do a decent one in just a few lines of code.": what about the good old x-squared generator? Breaking it is equivalent to factoring the modulus. The number is the until now unfactored RSA-640 number. Factor it and get $20,000. Or factor one of the larger challenges instead for more money.

    import time

    m = 3107418240490043721350750035888567930037346022842727545720161948823206440518 08150455634682967172328678243791627283803341547107310850191954852900733772482278 3525742386454014691736602477652346609 seed = 0

    def seed(): global seed k = 0 while 1<<(8*k) < m: k += 1 f = file("/dev/random", "rb") seed = 0 for i in range(0, k): seed = (seed<<8)|ord(f.read(1)) seed()

    def randbit(): global seed, m seed = pow(seed, 2, m) return seed & 1

    def random(n): k = 0 while 1<<k < n: k += 1 while 1: r = reduce(lambda x, y: (x<<1)|randbit(), [0] * k, 0) if r < n: return r

  • Arachnid (unregistered)
    ammoQ:
    This is not a random number generator, only an extremely bad wrapper around the already existing RNG rand().


    The following would be a real RNG:

      static int seed=1;
    double myRand(double minValue, double maxValue) {
    seed = (seed * 75) % 65537;
    return minValue+(maxValue-minValue)*(seed-1.0)/65536.0;
    }
    }


    Yes, a really bad one. Linear Congruential Generators like this tend to create really badly distributed random numbers, and that one is bad even for an LCG. See the wikipedia article and linked articles for more details. A much better (but still non-cryptographically secure) PRNG is the Mersenne Twister.

    Xepol:
    Actually, your generator here has a LOT less entropy than the rand function, which at least is seeded from the system timer when it ran, which, at least, is a truely random event. Reseeding on occasion can further increase entropy. Your solution is just a complicated, but FIXED series - it always starts with the same value and always follows the same path. Why do people feel the need to reinvent the wheel?? The end results inevitably seem to be a square.

    For one, the system timer is certainly not a 'truely (sic) random event' - it's a timer! It times things!

    "Anyone attempting to produce random numbers by purely arithmetic means is, of course, in a state of sin." --John Von Neumann.

  • (cs) in reply to divVerent

    This forum software and Python don't mix.

  • JB (unregistered) in reply to Daveh
    Anonymous:
    It would be convienent if GenerateRandomValue(1, 10) was equivalent to GenerateRandomValue(10, 1) (minor, but technically they mean the same).

    Not if the signature is GRV(min, max). (as it is in this case)
    It would then be a WTF all of its own if it was equivalent.
    If min is greater than max then the only logical return would be an exception.
    GRV(10, 1) (cannot return less than 10, cannot return greater than 1)
    JB

  • (cs) in reply to DZ-Jay

    DZ-Jay:

    As any other Wiki, it can be modified and updated at will by anybody.  Enjoy! :)

        -dZ.
     

     

    Not the c2 wiki anymore [:@] I understand the need, but dagnabbit, does anyone have the code word?

  • (cs) in reply to Cyresse

    Oh, and your "Brillant" page is up for deletion. Wiki Nazis. [:P]

  • Jon (unregistered)

    Glancing over the code reveals that it's returning a number in the range [min, max), so it can't sensibly return any number when min == max. Erroring out seems to be the correct behaviour, but it should at least error out in a sensible way. :-)

    Here are the problems I see with the code:

    • Doesn't use exceptions to report parameter errors
    • Screws up if the range is larger than RAND_MAX
    • More likely to return a value towards the beginning of the range
    • Fractional parts are unevenly distributed
    • Fractional part can be 1
    • Fractional part can be infinity (which can cause an infinite loop)
    • Uses a loop to simulate fmod()
    • The loop can be infinite if the range is really small
    • Too long
    • "0 == itsSeed" looks funny (if you're worried about writing "itsSeed = 0", turn on compiler warnings)
    • Eccentric naming conventions
    • Silly comments
    I still don't see the supposed way for it to crash. (If you were thinking of floating-point division by zero, this doesn't crash; it returns infinity.)
  • (cs) in reply to Cyresse

    Cyresse:
    Oh, and your "Brillant" page is up for deletion. Wiki Nazis. [:P]

    I think a "viral" campaign is more in order. You know, sigs with links, etc.

  • (cs) in reply to RFlowers
    RFlowers:

    Cyresse:
    Oh, and your "Brillant" page is up for deletion. Wiki Nazis. [:P]

    I think a "viral" campaign is more in order. You know, sigs with links, etc.

     

    My sig at another forum -

     

    Are you <FONT color=red>b</FONT>r<FONT color=red>i</FONT>l<FONT color=red>l</FONT>a<FONT color=red>n</FONT>t? Only Paula Bean knows for sure.

    Working on it. [H]

  • (cs) in reply to Arachnid
    Anonymous:
    ammoQ:
    This is not a random number generator, only an extremely bad wrapper around the already existing RNG rand().


    The following would be a real RNG:

      static int seed=1;
    double myRand(double minValue, double maxValue) {
    seed = (seed * 75) % 65537;
    return minValue+(maxValue-minValue)*(seed-1.0)/65536.0;
    }
    }


    Yes, a really bad one. Linear Congruential Generators like this tend to create really badly distributed random numbers, and that one is bad even for an LCG. See the wikipedia article and linked articles for more details. A much better (but still non-cryptographically secure) PRNG is the Mersenne Twister.



    Oh com'on, stop beating the simple old ZX81 PRNG. Of course it's not good enough for crypto or statistical stuff, but for computer games, it's quite ok.

    ZX81 functions
    (search for "6. for mathematicans only")

  • (cs) in reply to Maurits
    Maurits:
    ammoQ:
    Too easy. 0.9*maxValue could be actually smaller than minValue.
    Or larger (negative numbers)

    ammoQ:
    At least you should return minValue+(maxValue-minValue)*0.9
    This always works

    If you have a random number generator that returns results in the interval [ 0, 1 ], then your formula is a general way to return a result in the interval [ minValue, maxValue ]

    I just simply searched for "random range visual basic" in a search engine. The first page -the first link!- gives me an explanation of how to do this in one line.  (yes, I stubbornly use VB6)

    Rand = Int((High - Low + 1) * Rnd) + Low

    (But do not forget to initialize the generator by doing Randomize first) Was it necessary to write this function? No. The Genius could have encapsulated the above line, and added checks to it. Actually, this proves he is a genius: He did want to create a better random number generator, but didn't bother to do such trivial tasks as testing.

  • Janoz (unregistered) in reply to ammoQ
    ammoQ:
    Anonymous:
    aikimark:

    It seems to me that anytime the range is mostly negative, the routine will enter an endless loop condition.

    Example: <FONT face="Courier New">theMin := -15  theMax:=0</FONT>

    Also, it might just SEEM like an endless loop if <FONT face="Courier New">theMin</FONT> is a very large number, such as 3.1E31

    (this is my first WTF post -- thanks to Dennis Sherman for telling me about this site)

     

    Let's do the math with this.

    Range = 0 - -15

    Range = 15

    Next the for loop:

    for (; 15 <= aValue; aValue -=15)

    it still decrements aValue so eventually aValue will be less than 15

     

     



    range cannot be negativ, look at the first lines:

      if (theMin >= theMax) {
    // error in parameters, so return 0.0
    return 0.0;
    }



    Where do you see a negative range?? 0--15 = 15 > 0

  • (cs) in reply to Cyresse
    Cyresse:
    Oh, and your "Brillant" page is up for deletion. Wiki Nazis. [:P]


    Well, after reading their deletion policy, I do agree that it is non-notable, and somewhat of an in-joke to us.  Perhaps if the word gained momentum as a meme, but at the moment it hasn't.

    I do think it should be preserved in the "Bad Jokes and Other Deleted Nonsense" section, which holds anything that does not really belong in an encyclopedia.

        dZ.

  • (cs) in reply to Janoz
    Anonymous:

    Where do you see a negative range?? 0--15 = 15 > 0



    he meant 0 .. -15
  • Pepijn Schmitz (unregistered) in reply to chb
    chb:
    The naming of the variables kills me.
    (a|an|the|its)

    Maybe she's a "hungarian notation fundamentalist" *ducks*


    That's not hungarian notation. That would be including the type of the variable in its name. The place where I started work when I finished school used to do this (or at least, something similar), to indicate the scope of the variable: a/an means method parameter, my means local variable, the means class member.

    I quickly stopped doing it after I stopped working there though, as I find it to be just as arbitrary as including the type in the name. Sure, there are circumstances where it's nice to know, but there's a lot more about a variable which would be nice to know in some places, so why arbitrarily include this information, and not other information. IMHO it's better to make sure the program flow and variable names are clear and self-documenting.
  • Dagur (unregistered) in reply to Pepijn Schmitz
    [image]

    I hope this comes out right

  • (cs) in reply to Pepijn Schmitz
    Anonymous:
    chb:
    The naming of the variables kills me.
    (a|an|the|its)

    Maybe she's a "hungarian notation fundamentalist" *ducks*


    That's not hungarian notation. That would be including the type of the variable in its name. The place where I started work when I finished school used to do this (or at least, something similar), to indicate the scope of the variable: a/an means method parameter, my means local variable, the means class member.

    I quickly stopped doing it after I stopped working there though, as I find it to be just as arbitrary as including the type in the name. Sure, there are circumstances where it's nice to know, but there's a lot more about a variable which would be nice to know in some places, so why arbitrarily include this information, and not other information. IMHO it's better to make sure the program flow and variable names are clear and self-documenting.


    I do a lot of PL/SQL programming and I often use prefixes p_ for parameters and v_ for variables. The reason is that both parameters and variables in many cases refer to database columns, like in the following example:


    function getBarFromFoo(p_foo in foobar.foo%type) return varchar2 is
      v_bar foobar.bar%type;
    begin
      select bar into v_bar from foobar
         where foo = p_foo;
      return v_bar;
    end;

    prefixes like that make it easy to find appropriate names for variables and parameters.
  • (cs) in reply to ammoQ

    Yesterday, I found a little app that renders various attractors, from www.chaoscope.org.

    [noob math enthusiasm]
    How about an iterative function that spawns an attractor, so you can add another argument that indicates how random you want the number to be.

    Or maybe that would be a 'chaotic' number instead of 'random'.

    In any case it would technically prevent the theoretical situation of the same number reappearing over and over again.

    glee
    [/noob math enthusiasm]

    K. Back to reality.


          var Randy = Math.random();
          Randy = Randy.toString().replace('.','').split('');
          var RandysBrother = 0;

          for (var i=0; i < Randy.length; i++)
          {
              Randy[i] = parseInt(Randy[i]);
              RandysBrother += Randy[i];
          }

    Pseudo-reality, that is.
    This one is biased towards numbers between 50 and 100, but there is an occasional 20something.

  • (cs) in reply to dhromed

    Let's try that again, without the nbsps.

    var Randy = Math.random();
    Randy = Randy.toString().replace('.','').split('');
    var RandysBrother = 0;
    for (var i=0; i < Randy.length; i++)
    {
    Randy[i] = parseInt(Randy[i]);
    RandysBrother += Randy[i];
    }
  • (cs) in reply to md2perpe
    md2perpe:
    Mike R:
    Are you kidding??

    No. I really don't think that this has the same level of WTF:ness as most other postings, where it should have been obvious to the programmer that there must be some better way. At first sight this function looks okey, although it actually is not.

    Also, I don't think that most programmers are aware of the problems with floating point numbers; usually you don't need to care. Even Intel didn't get it right...



    I disagree. I think anyone, especially a brillant genius like this individual would have the insight to figure out "Hey, if I normalise the random number, then apply the range and add the minimum, I could get a number from min-max. It doesn't even take 6th grade math to work that one out!

  • (cs) in reply to Mike R
    Mike R:

    I disagree. I think anyone, especially a brillant genius like this individual would have the insight to figure out "Hey, if I normalise the random number, then apply the range and add the minimum, I could get a number from min-max. It doesn't even take 6th grade math to work that one out!


    I wouldn't quite say that it's obvious that this is the right way to do it. However, it is IMO definitely obvious that anything involving subtraction in a loop cannot be the right way.

Leave a comment on “Seriously, I'm A Genius”

Log In or post as a guest

Replying to comment #:

« Return to Article