I'm working in some software that includes a very basic library of math functions. I need to build a passable random number generator from these functions with as few manipulations as possible. If you're wondering what "passable" is, well, the bar has actually been set a lot lower than most RNGs. There will be no QC done on the results; it's just about as informal as you can get for something like this. Not too bad, so far, but it gets difficult when you consider the limitations on the tools I have to build this algorithm.
Seeding
The RNG must unfortunately be seeded by some pretty mundane data. Pulling two 6-digit integers is about as sophisticated as I can get. There is a system time/date function but it's only precise to whole seconds, and I can't convert it to a numeric string to be manipulated anyway. The two integers aren't even random themselves; one is basically a serial number that will increment by 1-5 or so with each iteration, and one is a different type of serial that won't be quite as predictable but a group of 20 samples will generally fall within the same range of, say, 50 or so.
Math
The software can perform some modest calculations. Here's a summary of the functions I have at my disposal:
Absolute value
Min/Max
Sin/Cos/Tan
Log10/Natural log/Exp (though it seems to just use
e as a 5-digit decimal for these calculations)
Polynomials (not sure how it works but it looks pretty limited)
Rounding/modulo (remainders)
Square root
...Plus all the basic arithmetic functions, including factorials and exponentials.
Other limitations
I can't find any documentation, but I'm not trusting this software to be able to keep track of any more than 12 significant figures. Also, it refuses to use string functions on numeric values and vice versa, no matter how many times you multiply things by 1. So, while you can get the middle 2 digits of a 10-digit number by using mod and round functions, you can't use the "mid(5,2)" function like you would be able to do with text. In short, everything has to kept strictly numeric. Finally, I can't do any fancy iterative stuff, as each number must be generated in complete isolation from any other number in the set.
Validation
Despite all the above handicaps, the one break I get is that, as I mentioned, the numbers don't have to be very random at all in the rigorous sense. Here's how I'll test it:
1.) Use the algorithm to generate 100 integers between 0 and 100 (or whatever, that detail doesn't really matter) based on the following seeding pattern: A couple 6-digit seeds will be chosen and one will be incremented for each trial while the other stays the same.
Seed 1 Seed 2
456789 543210
456789 543211
456789 543212
...
2.) Print out the list of numbers and hand it to our lab director, who is a pharmacokinetics PhD but not the Rain Man or anything.
3.) Let him eyeball it for a couple minutes and see if he notices any patterns emerge. If the numbers seem random, then that's good enough.
I've tried a few things so far, but I guess I'm not clever enough to come up with an algorithm that avoids, I dunno, every third number incrementing by a linearly decreasing amount, or something like that. There's always a subtle pattern that the layman (me) can perceive. I need something a little stronger without performing like a dozen of the above calculations. Anyone have a reasonably elegant solution?
Posts
CUZ THERE'S SOMETHING IN THE MIDDLE AND IT'S GIVING ME A RASH
EDIT: a quick search in wikipedia brings up tons of RNG info
!!!!▓▓▓▓▓Gravy?▓▓▓▓▓!!!!!!
!!!!!!▓▓▓▓▓▓▓▓▓▓▓▓▓!!!!!!!!!
of doom
CUZ THERE'S SOMETHING IN THE MIDDLE AND IT'S GIVING ME A RASH
I know squat about RNGs, btw.
There is also a method originally described by von Neumann which should be easy to implement with what you've got. Basically, you define Xi+1 as the "middle" digits of Xi^2. So, for instance, if your seed is 123456, then you define X1 as the middle digits of 15241383936, so maybe 41383, or 2413839. Obviously, "middle" can be defined in a variety of ways - I forget if there is a specific definition used in this method normally.
Should be simple enough - only arithmatic.
Oh yeah, and the numbers will be used to assign random test suites to batches of samples. It's an analytical lab, like CSI only our rooms are well-lit and none of us are snappy dressers.