- 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
When doing numerical simulations for some systems, and using perturbation theory it is important to be able to repeat some calculations with slightly different initial conditions, therefore we need the same random series. Another fact is the impossibility to have a true random number generator due to the computer deterministic nature.
What it is very important to understand is that from physics point of view random and chaos are not the same, that is why we talk about "deterministic chaos", meaning we can repeat simulations and get the same results. There are methods that allow us to cope with limited PRNG.
A similar missconception arises when people uses to say a double precision number is a real number. It is a good approximation to a real number. For the same reason it is impossible to have irrational numbers.
On the other hand, quantum systems appears to be chaotic (that is one way how we have quantum chaos), even it is possible to use some techniques from classical caos for analysing quantum systems, but under certain circumstances, while classical systems get stable, quantum systems remain chaotic, that means quantum effects are stronger than random effects, therefore quantum chaos in fact does not exist in the same sense as classical chaos.
Quantum systems appears to be nondeterministic, therefore the importance for the existence of a quantum computer (among other factors like world domination). There is a caveat: quantum systems can exist only on well defined states (that is why we talk about discrete energy spectrum), so if you measure it, it will aquire a valid state.
Admin
I see your lack of entropy and raise you:
When faced with the (apparant) need to generate a unique message ID, the developer of a custom (for "performance") messaging system at work decided that a PRNG wouldn't be enough. We needed to use the crytographically strong RNG!
Of course this eventually drained the Windows entropy pool until getting the next random number blocked, for hilarious results.
Admin
http://en.wikipedia.org/wiki/Fisher-Yates_shuffle
If you shuffle the total list beforehand every song will only play once.
Admin
Admin
That's easy for you to say...
Admin
At a company I worked at we decided that the best way to get good entropy would be to just hook up those motion capture balls to the intern and record the results all day every day... the intern... aka.. me.
Admin
The ISO 9899:1999 standard suggests a simple linear congruential generator in case you are not able to create your own PRNG:
According to Wikipedia this is used by a few platforms; but others usually change some constants.
Admin
For anything but toy programs you need a real PSRN. Like Boost.Random. You shouldn't expect the standard library to be able to tackle everything.
See http://www.boost.org/doc/libs/1_35_0/libs/random/random-generators.html. There's also a class for true random numbers, that feeds from /dev/urandom, /dev/random, or whatever you have to feed it with real entropy.
Admin
I probably would have done something like the following
MAXRAND := 65536;
num_cit := get_number_of_citizens_from_somewhere();
bucket_size := Ceil(num_cit / MAXRAND);
choose_bucket := random(num_cit/bucket_size);
choose_person_in_bucket := choose_bucket*bucket_size+random(bucket_size);
(do you notice I haven't programmed in a while? ;-) So please shout WTF when you read an error )
If you have to choose from more than MAXRAND*MAXRAND than you'd need a second recursion of course... but I somewhat doubt that you need to choose jurors out of the whole world population :)
Admin
Essentially you'd be using another (really simple) random number generator over the top to cover up the flaw in the "42" one I described.
Addendum (2008-08-12 09:43): Actually, I don't think there is any real limit on what prime is used for what I called the "low prime", as long as it isn't really tiny and isn't the same as what I called the "high prime". It can safely be larger.
Admin
You need better peers, obviously ;^)
Admin
rand(rand(rand(rand(rand(rand(rand(rand(rand(rand(rand()*rand()+rand(rand()-rand())))))))))))
Admin
Hay guyz, am I too late for the XKCD reference?
Admin
(rand() & 16)
WTF?
Doesn't that return 16 or 0?
Admin
I'd just like to comment that true randomness isn't possible physically, literally, or computationally.
Just saying. You can achieve 'effective' randomness "for your purposes", but there's no actual such thing.
Admin
Yes, the orginal question I replied to was about whether the result of the next roll could be guessed by looking at the results of previous rolls. That's not a problem with distribution or results - it's a problem with determinism and lack of entropy. Other posters suggested getting real entropy using temperature-sensitve resistors or radioactive decay.
This problem crops up in crypto, but also in gambling machines. I remember a news story about a Keno machine at a casino that was being shut down every night, and restarted ever morning; whereupon it would give the same set of numbers that it gave the day before. Eventually the casino noticed, but not before some patrons took advantage of the pattern.
That's a WTF indeed, and a worse one that the original post. The author of that code (or the library used) was apparently seeding with the current time since power on, which was always the same since the time it took for the machine to boot was constant! (Seeding with "time since Jan 1 1970" would have helped, if the system knows the current date. Not all embedded systems do. Even better, a simple "press button A to continue" before seeding would have made the machine less predictable! )
Admin
Implement your own is strongly advised against.
Admin
Admin
Yes, this should work as well. I agree that the bias should disappear. Clever.
Admin
Most of the random generators I have used return numbers in the range [0 <= rand() < 1]. When using the method I used, rand() * 10 yields [0.0 <= (rand() * 10) < 10.0]. At this point, the number is real, with the lower order bits as fractional. Taking the integer of this, in effect, "clips off" the low-order bits, meeting the requirement above.
The problem I was discussion arises only because, despite the float range, there are still only 32,767 or 65,536 distinct float values that can be returned, so that if the multiplier is large, values get skipped at semi-regular intervals. Especially if the multiplier is larger than the distinct value set.
Admin
This falls afoul of the same problem as rolling two dice together and counting the spots. Statistically, for the dice, getting exactly 7 spots is 12 times as likely as getting 2 spots or 12 spots. Over a large number of rolls, the spots form a nice bell curve.
So the above would tend to choose jurors in the range surrounding the halfway mark (500,000 in the range of 1 to 1,000,000) much more often than those near 1 or 1,000,000; which would be undesirable.
Admin
This is a joke, right?
Because clearly the premise in the article is complete nonsense. The output of a PRNG is predictable; the output of nested PRNGs is EXACTLY as predictable as the output of a single one. The entropy of either approach is zero.
As Knuth points out (in Volume Two): "Random numbers should not be generated with a method chosen at random" -- such as the one described in this article.
For those who want to read a technically sound discussion of random numbers and how to generate them, go read RFC 1750
Admin
I once discovered the following code to create a checksum based upon a string value:
function CalculateCRC(const GUIDStr: string): string; var I: Integer; CRC: LongInt; begin CRC := 0; for I := 1 to Length(GUIDStr) do if (GUIDStr[I] in ['0'..'9']) then CRC := CRC + (Ord(GUIDStr[I]) * 256 + 5); Result := IntToHex(CRC, 5); end;
The purpose of this code was to create an unique value by calculating a checksum over some random string value. Of course, a GUID was used to create this random string that could be used as identifier and of course it only calculates with the numbers inside this GUID. Fortunately, it was made more unique again by appending the result of this function to the original GUID and then another checksum routine is used to calculate a second CRC. Finally the code that uses this "unique" CRC also used a timestamp to make it a bit more unique. Appending year, month, day, hours, minutes, seconds and milliseconds and there you are, with a nice and unique value...
Yeah, I've suggested to replace it with just a GUID and they looked at me as cows look at oncoming trains...
Admin
We have an old saying from the country I'm from. If you're going to try to bang in screws with lots of different kinds of plyers, don't blame the plyers.
Admin
Yea, or you could just make it really really super ueber OMFG NO WAI lolcats random: http://random.org/
Admin
Don't search for a random string. Just search for "marf" and pick a random word from the search results. Then search for that, if you want. The more searches you do, the more the fluctuations in the internet will improve on your entroy.
Admin
I'm not sure why this is such an issue.
Worthwhile randomizers expect a 'seed'. Give it something different every time, and you'll get something fairly random. Try current time or maybe system clock ticks (UNIX and variants can provide this as an integer). On multiple random draws, wait a little while between seeds.
Admin
Almost forgot.
For all you random number purists, check out http://www.lavarnd.com/
I've noticed that the random Corporate Memo generator at http://www.lavarnd.com/cgi-bin/corpspeak.cgi does a scary job of emulating upper-echelon fatheads.
Admin
well, I thought the above code would remedy that by first choosing a "container" with several people in it and then one out of these. So the first random number chooses a bucket, the second chooses in the bucket...
My last line choose_person_in_bucket := choose_bucket*bucket_size+random(bucket_size); just returns the "number" of the person chosen.
Perhaps I write a small simulation tomorrow...
Admin
hmmm, how fast "tomorrow" comes ;-) my code gives the expected result:
Implementation in freepascal:
USES crt,math;
CONST MAXRAND = 16; num_cit = 64; num_runs = 1000000;
VAR bucket_size, chosen_bucket, chosen_person : word; results : ARRAY[1..num_cit] of Cardinal; i : Cardinal;
begin randomize; bucket_size := ceil(num_cit / MAXRAND); for i:=1 to num_cit do results[i]:=0; for i:=1 to num_runs do begin chosen_bucket := random(ceil(num_cit/bucket_size)); chosen_person := chosen_bucket*bucket_size+random(bucket_size)+1; Inc(results[chosen_person]); end; for i:=1 to num_cit do write(results[i],' '); end.
Result: 15746 15527 15417 15536 15648 15609 15796 15464 15485 15537 15449 15687 15778 15933 15790 15631 15693 15651 15592 15751 15629 15745 15632 15568 15649 16022 15558 15685 15570 15544 15674 15453 15472 15636 15599 15565 15785 15229 15444 15641 15888 15305 15537 15784 15682 15491 15604 15460 15702 15632 15815 15721 15638 15706 15672 15709 15606 15563 15582 15564 15555 15630 15713 15621
Looks somewhat equal-distributed to me :)
And now it's 5:25 AM... time to watch some anime, then go to sleep :)
Admin
Admin
Old Slashdot post, but so on topic: Debian Bug Leaves Private SSL/SSH Keys Guessable Debian package maintainers tend to very often modify the source code of the package they are maintaining so that it better fits into the distribution itself. However, most of the time, their changes are not sent back to upstream for validation, which might cause some tension between upstream developers and Debian packagers. Today, a critical security advisory has been released: a Debian packager modified the source code of OpenSSL back in 2006 so as to remove the seeding of OpenSSL random number generator, which in turns makes cryptographic key material generated on a Debian system guessable. The solution? Upgrade OpenSSL and re-generate all your SSH and SSL keys. This problem not only affects Debian, but also all its derivatives, such as Ubuntu.
Admin
If you followed this bug closely you'd have noticed that the debian developer making the faulty change asked in upstreams developer mailing list if this was OK and got some vague "yes, do so if it helps with debugging"... When mentioning this upstream the reaction was something like "what? this is not a mailing list our developers regularly read despite having -devel name and mentioning this would be the right place in the dosumentation... you should have asked elsewhere... and besides, that a person still now in the devel team told you so doesn't mean it's OK"
Admin
Knuth's Comment: Do not select random number generating algorithms at random.
Admin
Admin
I'm not a programmer, so maybe I'm the WTF here, but that looks wrong to my untrained eyes. Wouldn't that algorithm bias you severely to the upper half of your numbers?
I'm looking at that, and it seems that only 1 out of however many random numbers you can get would you ever get a number below half.
Wouldn't you want to weave the bits together or something odd like that?
Admin
Every PRNG (Pseudo-RNG) automatically has this property...
Wikipedia (yeah, I know... biggest trash dump of the human mind ever...) says: "A PRNG can be started from an arbitrary starting state, using a seed state. It will always produce the same sequence thereafter when initialized with that state. The maximum length of the sequence before it begins to repeat is determined by the size of the state, measured in bits." (http://en.wikipedia.org/wiki/Pseudorandom_number_generator)
Admin
The point is, it's still not random, but you would need to know the system state on each call, past and future to predict the next random number, as opposed to just discover the seed/internal state.
Admin
Compile this program in MS C++ version 13.00.9466:
#include <stdio.h> #include <stdlib.h>
int main() { int ix; for (ix = 0; ix < 100; ++ix) { srand(ix); printf("Called srand(%d): rand() = %d\n", ix, rand()); } return 0; }
You get: Called srand(0): rand() = 38 Called srand(1): rand() = 41 Called srand(2): rand() = 45 Called srand(3): rand() = 48 Called srand(4): rand() = 51 Called srand(5): rand() = 54 Called srand(6): rand() = 58 Called srand(7): rand() = 61 Called srand(8): rand() = 64 Called srand(9): rand() = 68 Called srand(10): rand() = 71 Called srand(11): rand() = 74 etc.
That doesn't seem right to me.
Admin
msvcrt.dll random algorithm is: signed long int rand_value; void srand(unsigned int seeed) { rand_value = seed; }
int rand(void) { rand_value = rand_value*0x343FD + 0x269EC3; return (rand_value >> 16) & RAND_MAX; }
(Additionally, its version is thread-safe by having rand_value into thread storage).
Admin
As a dinosaur, I do recall the days when you really, truly could not trust the rand functions from, say, Applesoft Basic on the Apple ][, and thus implemented algorithms which were taught in classes for doing such (yes, they used to teach us how to do it).
Being sensible, I always generated a Chi-Squared test with that to verify that it was doing what I expected it to be doing... but I did another test, which was suggested somewhere, and struck me as pretty effective -- it once showed a flaw which the Chi-Squared test hadn't caught.
A visual test: Whatever the rez of your screen was, generate a pair of numbers within those bounds and plot a point. Repeat ad nauseum. With those old 1 mega hertz and less processors, this actually took time, so you would run it and just look up once in a while. If there was a real flaw in the generator, it usually would show up as a "hole" (or, alternately, an "organization", like a striping pattern) in the screen thus generated. A properly functioning RNG would look like static, and show no favorite areas... Ideally, if the system in question allowed you to read the color of an existing pixel, you could also add a third dimension to the test and increment the color so areas would shade differently, with hot spots being a sign of failure just like holes.
Admin
Also, rand() & 16, a bitwise operation, can only evaluate to 0 or 16, since 16 = 0b10000.
Admin
Actually the worst failure of this snippet is it calls srand. You're pretty much bypassing the algorithm if you call srand everytime you want a random number.
Admin
Arua ROSE zuly is used to upgrade experience, you can point him food to plus use of blood is do not rose online zuly, more a task bar to complete the task can be a lot of rose online zulie subsidies and experience points, as long as the spend Rose zuly bought some food to the blood of drugs sufficient to meet those Xiaoguai. To transfer the time to consider a good career you want to turn, attribute point will come to Canada based on your job and your rose zulie.
Admin
I was once forced into introducing a "better" random number generator than the "pseudo" random method of using rand and srand, as the unique identifier for DB tables. (Really, really stupid idea.)
So, I dazzled them with my "BS" in Engr., a literally duct taped together copy of a college Calculus book, that included graphs of sinh and cosh. I fed these as the seed to srand with the current system time, and voila, came up with a "new" random number generator.
So, being the early '90s, I named the algorithm, TAFKAP and the correlary algorithm TAFKAV.
Those stand for the "The Artist Formerly Known As Prince", Sign(h) of the Time? And the "Artist Formerly Known As Vanity.
About a year later, while working for a different job in the same company, I was asked to review some code from the previous project and found that not surprisingly, the unique id's were still not enough, so the new coder added a for loop to try seeding srand 10 times.
Admin
https://cialiswithdapoxetine.com/ cialis online