View Full Version : Random Numbers in StormFront
sahra
02-11-2005, 04:29 PM
I'm musing over ways to generate a series of pseudo-random numbers in StormFront (don't worry -- not for horses and dragons ... sigh). Anyone have a good idea for this?
Toxicvixen
02-11-2005, 04:48 PM
What for?
Artha
02-11-2005, 06:27 PM
I don't believe there's a way to do this outside of rolling a dice (which you have to have in game) and using matches for the outcomes.
sahra
02-13-2005, 02:36 AM
I want to cycle Tips of the Day and other ephemera in non-repeating ways. Not an application requiring a perfect distribution. I suspect Simu kept a RND() out of StormFront, deliberately, because it's useful for so many 'evil' things (from script-hunting to gambling scripts).
You're right -- I thought about that: one could use dice, or one of those 'flipping coins.' But the user would have to have the prop(s), and the method would be kinda noisy.
I think I have it, though. I'm going to generate a seed by counting the number of vowels in the current room description, pass it off to a standard RNG algorithm, then use the result as the new seed (so I only have to set the seed once unless the variable store is erased).
The one I've coded here is a bad old IBM RNG called RANDU, tweaked to avoid blundering across StornFront's limited math word-size. Seems to work fine (that is, the output looks random to me). I set up this test to show the output of a 100-sided die, but you could mask this to return small random integers in any range. The first time you run it, enter a random integer argument as the seed. Afterwards, run it w/o args to produce the next random integer in series.
DEBUG OFF
setvariable a 1028
setvariable per 65539
if_0 goto getseed
goto random
getseed:
setvariable seed %1
# modified IBM RANDU algorithm: x2 = ax1 % per
random:
counter set %seed
counter multiply %a
setvariable ctr %c
counter divide %per
counter multiply %per
setvariable ct2 %c
counter set %ctr
counter subtract %ct2
setvariable seed %c
# counter now contains large random integer
# masking example: 0 - 99 (100-sided die)
setvariable ctr %c
counter divide 100
counter multiply 100
setvariable ct2 %c
counter set %ctr
counter subtract %ct2
echo %c
Electrawn
02-16-2005, 12:36 AM
You have two numbers available to you that change randomly and sequentially.
MATCHRE is SF only.
One is the number of players on who
and the other is time.
So...
MATCHRE ZERO Active Players: (.*?)0
MATCHRE ONE Active Players: (.*?)1
MATCHRE TWO Active Players: (.*?)2
...
MATCHRE NINE Active Players: (.*?)9
PUT who
MATCHWAIT
Or
MATCHRE ZERO It is (.*?):.0
MATCHRE ONE It is (.*?):.1
MATCHRE TWO It is (.*?):.2
...
MATCHRE NINE It is (.*?):.9
PUT time
MATCHWAIT
If you need just a either/or random number, keep a shiny coin on you.
MATCH ONE heads
MATCH two tails
put toss my coin
MATCHWAIT
If you need to generate more than one random number in a minute or need a more random random number use these as seeds.
-Elec
sahra
02-17-2005, 01:59 AM
Cheers!
Electrawn -- that's great! I knew life could be simpler.
Electrawn
02-17-2005, 02:21 AM
Regex is never simpler...only shorter. :)
-Elec
sahra
02-17-2005, 01:05 PM
True -- all forms of RegEx are evil. Doubly evil that SF doesn't give us a way to capture parentheticals in variables.
BigWorm
02-18-2005, 05:48 AM
Time works alright for pseudo random depending on how close the checks are. For a tip of the day or whatever, it would be fine, but not for something like a gambling script.
I never thought of using number of people on. That's a really good idea.. Don't think it would be easy to make it work in the Wizard though
sahra
02-21-2005, 02:14 AM
Well, you only need one "random number" for the seed, if you use an algorithm to generate additional numbers. But is there a semi-decent RNG that can be implemented, and made to run fast enough to serve, using just the Wizard's COUNTER ADD and COUNTER SUBTRACT? In theory, sure, you can use ADD to simulate multiplication and SUBTRACT to simulate division. But it would run really, really, really slowly ....
You could always cheat and take about 400K of random integers from a decent RNG and arrange them in a table, then use a seed to choose a random starting-point in the table.
Electrawn
02-21-2005, 05:13 AM
Or...
Write a mini proggie to use an HWND hook that checks to see if wizard is running and kills it. Release it as PSINet 2.0. Make sure to time it with one of Microsofts first tuesday of the month super patch specials.
Simu ends up with 100s of tech calls, MS gets blamed. Dell sees unexpected revenue increase from surge in rural dial up users buying fast computers....
...strategically timed Dell stock buy = Profit!
Solves that pesky Wizard RND problem.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.