- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
<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>
Admin
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:
Admin
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?
Admin
After all the half-naked chicks wallpapers I've seen on co-workers screens, I wonder [:D]
Admin
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?
Admin
No, it's a class variable. She refers to it as this->itsSeed on the next line.
Admin
"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?)
Admin
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.
Admin
Alex, I'm sending you my dry cleaning bill. My shirt got all ruined when my eyes started bleeding. Bastard!
Admin
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."
[:)]
Admin
Too easy. 0.9*maxValue could be actually smaller than minValue. At least you should return minValue+(maxValue-minValue)*0.9
Admin
Or larger (negative numbers)
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;
}
Admin
Note that it doesn't particularly matter whether A > B, A < B, or even A = B.
Admin
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.
Admin
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?
Admin
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
Admin
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...
Admin
"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.
Admin
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.
Admin
Hum... If her real name is Paula Bean, I would suggest we anonymize it, just in case, to avoid any, hum, legal entanglements.
-dZ.
Admin
No, it's a pseudo-random number generator.
Admin
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.
Admin
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.
Admin
Since it doesn't even return a valid pseudo-random number, I definitely think it's a WTF.
T
Admin
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.
Admin
I haven't said that it isn't a WTF.
Admin
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)
:)
Admin
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
Admin
range cannot be negativ, look at the first lines:
Admin
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
Admin
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.
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.
Admin
This forum software and Python don't mix.
Admin
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
Admin
Not the c2 wiki anymore [:@] I understand the need, but dagnabbit, does anyone have the code word?
Admin
Oh, and your "Brillant" page is up for deletion. Wiki Nazis. [:P]
Admin
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:
Admin
I think a "viral" campaign is more in order. You know, sigs with links, etc.
Admin
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]
Admin
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")
Admin
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.
Admin
Where do you see a negative range?? 0--15 = 15 > 0
Admin
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.
Admin
he meant 0 .. -15
Admin
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.
Admin
I hope this comes out right
Admin
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.
Admin
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.
Pseudo-reality, that is.
This one is biased towards numbers between 50 and 100, but there is an occasional 20something.
Admin
Let's try that again, without the nbsps.
Admin
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!
Admin
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.