Page 1 of 1 1
Topic Options
#67198 - 2002-06-18 03:55 PM srnd rnd not random, help guys!
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
good topic for thread is a and z...

so, I have this little script which should give nice little sound every 45-75 seconds.
code:
$s=45
$b=75
$log=@scriptdir+"\ajat.log"

"Running Random beep every $s - $b seconds"
? ? "log is being written to $log"
? "to stop the script press any letter"

$b=$b-$s
run '%comspec% /c echo starting time logging at @time >> "$log"'

do
$=srnd(@msecs)
$sleep=$s+1+rnd($b)
play "0g5000f12d128t5g5000f12d128t"
run '%comspec% /c echo @time >> "$log"' at(5,20) @time
sleep $sleep
until kbhit()

then I check after a while the log and it has:
quote:

starting time logging at 15:32:31
15:32:33
15:33:22
15:34:10
15:34:57
15:35:45
15:36:35
15:37:25
15:38:15
15:39:04

in it...
this means that randomness is only 1-2 seconds.
when it should randomize between 0-30!

is this normal in kix's random generator or is my syntax totally wrong?
_________________________
!

download KiXnet

Top
#67199 - 2002-06-18 04:12 PM Re: srnd rnd not random, help guys!
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
I just ran your script.. It seems to work for me.. let me test some more.

Brian

Top
#67200 - 2002-06-18 04:14 PM Re: srnd rnd not random, help guys!
DrillSergeant Offline
MM club member
*****

Registered: 2004-07-09
Posts: 1164
Loc: Eijsden, the Netherlands
Hi Lonk,

Try doing the 'seed' thingie before the 'DO'-loop... I think it will work a bit better [Wink]

Ok... some explanation is in order I guess... [Embarrassed]

This:
code:
for $i = 1 to 100
$=SRND(@MSEC)
? RND(30)
next

gives me one hundred zero's...

This:
code:
$=SRND(@MSEC)

for $i = 1 to 100
? RND(30)
next

gives me one hundred perfect random numbers between 0 - 30...

[ 18 June 2002, 16:19: Message edited by: DrillSergeant ]
_________________________
The Code is out there

Top
#67201 - 2002-06-18 04:32 PM Re: srnd rnd not random, help guys!
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ah.
and I thought it would be better to initialize it on every loop!
_________________________
!

download KiXnet

Top
#67202 - 2002-06-18 04:37 PM Re: srnd rnd not random, help guys!
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
Actually, I created a script just for the heck of it to test how well the RND functions.. turns out pretty well. I haven't done a proper statistical analysis, but... this script at least tests that there is convergence when taking the average as the number of rolls approaches infinity.
code:
break on
$avg1 = 0
For $g = 1 to 100
SRND(@MSECS)
$x = 1000
DIM $Y[$x]
$Z = 1
For $n = 0 to $x
$j = RND($Z)
$Y[$n]=$j
Next

$j = 0
For $n = 0 to $x
$j = $j + $y[$n]
Next

$avg = (CDBL($j)/($x+1)) * 2
$avg1 = $avg1 + $avg
Next
CDBL($avg1)/100

Brian

Top
#67203 - 2002-06-18 04:44 PM Re: srnd rnd not random, help guys!
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
sweet...
nice to see that you have creative ability to make yourself something todo. not married, I quess...
_________________________
!

download KiXnet

Top
#67204 - 2002-06-18 04:47 PM Re: srnd rnd not random, help guys!
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
ha ha ha.. nope, not married... not anytime soon, either (at least I hope not!)

Brian

Top
#67205 - 2002-06-18 04:49 PM Re: srnd rnd not random, help guys!
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
not working.
I still get
17:33:44
17:34:33
17:35:22
17:36:11
17:36:59
17:37:46
17:38:34
17:39:24
17:40:14
17:41:04
17:41:53
17:42:42
17:43:31
17:44:19

hey...
roger, if it does work, cause you wrote @msec and not @msecs?
_________________________
!

download KiXnet

Top
#67206 - 2002-06-18 04:55 PM Re: srnd rnd not random, help guys!
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
I don't think SRND returns a value...

Instead of $=SRND(@msecs)

It should be:

SRND(@msecs)

Brian

(although I doubt this will fix the problem.)

[ 18 June 2002, 16:57: Message edited by: BrianTX ]

Top
#67207 - 2002-06-18 05:10 PM Re: srnd rnd not random, help guys!
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
Ok.. this should work:

code:
$s=45

$b=75

$log=@scriptdir+"\ajat.log"

CLS

"Running Random beep every $s - $b seconds"

? ?"log is being written to $log"

? "to stop the script press any letter"

$b=$b-$s

run '%comspec% /c echo starting time logging at @time >> "$log"'


srnd(@msecs)

do

$sleep=$s+1+rnd($b-1)

play "0g5000f12d128t5g5000f12d128t"

run '%comspec% /c echo @time >> "$log"' at(5,20) @time

sleep $sleep
until kbhit()

Brian

Top
#67208 - 2002-06-18 05:17 PM Re: srnd rnd not random, help guys!
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
A bit OT, but @MSECS will always return a number in the range 0-999. Depending on the algorithm used you could end up with similar results every run.

@TICKS might produce a better spread, or even Val(""+@TICKS+@MSECS)

Top
#67209 - 2002-06-18 05:20 PM Re: srnd rnd not random, help guys!
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ridge ( [Big Grin] ) i thought the same but looked at:
http://www.gwspikval.com/jooel/scripts/kix402.html#RND
and decided (don't ask how or why) that srnd can't take large numbers as input...

cheers,
_________________________
!

download KiXnet

Top
#67210 - 2002-06-18 05:24 PM Re: srnd rnd not random, help guys!
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
it works!
log-file:
starting time logging at 18:16:11
18:16:13 - waited 48 seconds
18:17:03 - waited 72 seconds
18:18:17 - waited 58 seconds
18:19:17 - waited 74 seconds
18:20:33 - waited 75 seconds
18:21:50 - waited 52 seconds

i did some error stuff to the script and turned lines upside down...
there was bug in my script (pretty normal and I feel pretty stupid to be in the big M and still get these stupid scripting bugs)...

thanks to you all.
now I can get the heck out from work.
_________________________
!

download KiXnet

Top
#67211 - 2002-06-19 12:31 AM Re: srnd rnd not random, help guys!
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Slow down and write some better code there Mr. M club. [Big Grin]

You ought to be passing me by sometime this week or next at the rate your going.

Oh well, can't stay ahead forever. [Roll Eyes]

Top
#67212 - 2002-06-19 12:37 AM Re: srnd rnd not random, help guys!
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
doc, I'm just taking back what belonged to me. [Mad]
got rad and kent allready...
you will probably be the next.
then it's all open sKy. les is to be catched though but it takes more than couple of months.

actually, there are many high posters coming from behind and I must keep up the speed or I'll stumble in their feet!

I surely advice you too to run for your life!
_________________________
!

download KiXnet

Top
#67213 - 2002-06-19 12:41 AM Re: srnd rnd not random, help guys!
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
pfffttt. hmmm... Reminds me of the story of the Tortoise and the Hare.

You run along now sonny boy and do what you need. Eat some of those wild oats if you must. I'll be here waiting when you get back. [Cool]

Top
#67214 - 2002-06-19 02:48 AM Re: srnd rnd not random, help guys!
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
EH DOC! There's quality (you) and then there's quantity (me) but Jooel set his bar lower still. [Big Grin]
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#67215 - 2002-06-19 06:02 AM Re: srnd rnd not random, help guys!
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
lol
Top
#67216 - 2002-06-20 12:37 AM Re: srnd rnd not random, help guys!
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
mmm...

I'm coming...
_________________________
!

download KiXnet

Top
#67217 - 2002-06-19 02:44 PM Re: srnd rnd not random, help guys!
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Jooel,

You may have me and Rad, but work does come first. (ouch!)

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1046 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.059 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org