• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Interesting (i think?) problem generating random numbers

eLiu

Diamond Member
Hey folks,
So I have 2 test cases that run within ~1 minute of each other. Basically I have this: 1 function is known to work; the other function is supposed to have the same behavior (each one is written a different way...the why is not important).

Anyway, I want to be able to run random test cases to compare the results from both functions. Right now I used a prng (twister) to do this, seeding both functions with the exact same number. Unfortunately this means I need to change the seed every time I run a test case.

So what I would like is to seed the prng with a different number each time I run the test case, BUT I need both functions to receive the same number. And since they don't run at the exact same time, using the system time is not a viable option...

Any ideas?

Thanks,
-Eric
 
It's been a while since I've done any programming, but why couldn't you generate your list of random numbers ahead of time and use the list as the same source of data for both test cases?
 
Generate a random number in the first program based on whatever (system time or anything). Save it. Use it in the second program.

Seems simple enough to me.
 
date possibly? perhaps you could add the month+day+year. If it runs more than once per day maybe increment the initial value?

also, if they run within 1min you could use time, just only use the hour.

we need a little more information I think. Are they called by a parent program? Could you pass a variable from one to another?
 
Yeah I guess I didn't provide enough info...sorry :/

Each function is called by a parent program that's responsible for comparing output and such. The way the system is set up, the two functions CANNOT communicate with each other--ever. And it's not my place to screw with the current setup, so there's no modifying it.

So I've considered using coarse-time (e.g. hours), but so far I've shyed away from it b/c I want a solution that could work for functions that take much much longer to test.

But even then with coarse-time, if I run the test more than once in an hour, it'll just be testing on the same numbers again.
^^That's the reason I don't pre-generate numbers...I want new test cases for each run 🙂
 
~1min is a guess. And it's different every time...like other jobs/background processes running; the differences are on the order of seconds, but still this is a relatively simple task. And if the data doesnt' start off exactly the same, then it'll never work...
 
Then use a variable.

The code should be the same on each machine.

<?PHP
$var = "10";

//run the test
$var++;
?>

The variable will increase by one each time, giving each machine the same number if equal number of tests are being performed.
 
Have the main control harness that calls both functions write a seed to a file or global variable (what LoKe was getting at?). Or have a separate "planter" applet write the seed to a file before the test harness runs.


<--- hmm, time to stop posting?
 
Originally posted by: DaveSimmons
Have the main control harness that calls both functions write a seed to a file or global variable (what LoKe was getting at?). Or have a separate "planter" applet write the seed to a file before the test harness runs.


<--- hmm, time to stop posting?

You do know his head asploded, right? Simplifying things is the only way to go, unless you feel like coding it all for him, and I certainly don't. 😉
 
Generate a list (array) of random numbers, then scroll through the list providing that value to each function.

i.e. (very bad pseducode I know....it's been awhile)

MyRandNumArray[1..100] <---- Array of Random numbers

For X = 1 to 100
...MyRandNumArray[X] = Rand()
Next X

For X = 1 to 100
...Call Function1(MyRandNumArray[X])
...Call Function2(MyRandNumArray[X])
Next X


Disclaimer: Programming not my expertise any more. But I try. 🙂
 
LoKe, that sounds like a good idea to me... methinks I'm taking your solution 🙂

Thanks everyone!
 
Back
Top