forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


RANDOM Numbers

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Mon Mar 11, 2002 9:36 pm    Post subject: RANDOM Numbers Reply with quote

I'm not real sure if this is a bug or not, but if I compile the code below, everytime I run the compiled program it gives me the same numbers. If I compile it again I get a different set of numbers, which are the same everytime I run it.
Is it just me?
Code:

info @RANDOM(1,15)
info @RANDOM(1,15)
exit

_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Thu Mar 14, 2002 1:55 am    Post subject: Reply with quote

Has anyone tried this? I'd like to see if it's just me..
_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
marty
Professional Member
Professional Member


Joined: 10 May 2001
Posts: 789

PostPosted: Thu Mar 14, 2002 12:49 pm    Post subject: Reply with quote

Well works for me after I compiled.

info @random(1,15) I got 13
info @random(1,15) I got 4

Using VDS 4.02 on Windows 2000 PIII 733

Wink
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Thu Mar 14, 2002 5:26 pm    Post subject: Reply with quote

What I mean, is that when I open the program after compiling I get say, 13 and 4. Then if I close the program and open again, I will get 13 and 4 again, the same thing again and again until I recompile..
_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
marty
Professional Member
Professional Member


Joined: 10 May 2001
Posts: 789

PostPosted: Thu Mar 14, 2002 6:34 pm    Post subject: Reply with quote

Well now I do it like you said and I have always the same results when re-running the same exe again and again...

I guess that's a bug...strange... 8O

Cool
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
easy rider
Valued Newbie


Joined: 10 Sep 2001
Posts: 26
Location: Netherlands

PostPosted: Thu Mar 14, 2002 7:51 pm    Post subject: Reply with quote

hi snarlingsheep

I don't no why but maybe you have to use it in a dialog, then it works fine
see code below
Code:

dialog create,test,-1,0,200,100
dialog add,text,t1,10,10
dialog add,text,t2,30,10
dialog add,button,b1,70,10,,,new
dialog show
:b1button
%A = @random(15)
%B = @random(15)
dialog set,t1,%A
dialog set,t2,%B
:evloop
  wait event
  goto @event()
:close 
exit


see ya rene
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Thu Mar 14, 2002 8:33 pm    Post subject: Reply with quote

easyrider:
Nope, same result. If you have compiled your example, open the EXE and look at the numbers it gives, close it and then open the EXE again. They will be the same.
I opened it, got 7 and 12, hit new, got 6 and 12. Closed it. Opened it again, got 7 and 12, hit new, and got 6 and 12 again.
It's like they are saved somewhere when you compile..

Another bug to send to SADE?

_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
Tommy
Admin Team


Joined: 16 Nov 2002
Posts: 746
Location: The Netherlands

PostPosted: Thu Mar 14, 2002 10:21 pm    Post subject: Reply with quote

It's not a bug, you should first seed the random number generator using the RANDOM command with a value that varies each time. This is the case in almost any other programming language too.

Tommy
Back to top
View user's profile Send private message Send e-mail Visit poster's website
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Fri Mar 15, 2002 3:37 am    Post subject: Reply with quote

Color me stupid..but then how do you go about getting completly random numbers?
With vdsrnd32.dll it just picked out a number between whichever numbers you used. VDS does the same when you run the program from the editor, and just use @random(1,15).
Sheep need bigger brains..

_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Fri Mar 15, 2002 6:56 am    Post subject: Reply with quote

Nope, I don't think that you need bigger brains, Sheep. I think that perhaps
VDS needs a better help file because it's not very clear on this issue.

But if you wanna seed your number gen, you might use something like
this:

Code:

OPTION DECIMALSEP,.
%%seed = @EXT(@DATETIME())
%%seed = @SUBSTR(%%seed,@DIFF(@LEN(%%seed),3),@LEN(%%seed))
RANDOM %%seed


This seeds the number gen with a random 4 figure number - don't seed it
with very long numbers because that will produce an input error.

Greetz
Dread

_________________
~~ Alcohol and calculus don't mix... Don't drink and derive! ~~

String.DLL * advanced string processing
Back to top
View user's profile Send private message
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Fri Mar 15, 2002 7:17 am    Post subject: Reply with quote

That works for me.
Thanks Dread Smile

_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
Lucyfer
Newbie


Joined: 06 Apr 2002
Posts: 16
Location: Quebec/Canada

PostPosted: Sat Apr 06, 2002 2:53 pm    Post subject: Reply with quote

Hi, glad to be joining the forces! Smile

On the RANDOM subject, I've got a couple of points.

- The seeding is usually done with the @datetime() function, with the undocumented option snd. Weird, I can't find out WHERE I found about this... VDSrnd16 helpfile?

Code:
RANDOM @datetime(snd)


- The limits. Using the next code :

Code:
%d = @Random(any number,any number)

Might not always give what's expected.
Sometime <max> will be picked, sometime not, but I can't point to why. I patched my code so it's always picking numbers starting with 0
Here is an example :

Code:
rem -- Pick something between 101 and 120 --------
rem CODE                               TRACE
    %%Min = 101
    %%Max = 120
    %%Range = @Diff(%%Max,%%Min)       Range = 19
    RANDOM @datetime(snd)
    %D = @Random(@Succ(%%Range))       @Random(0,20)
    %Random = @Sum(%%Min,%D)           101+D

rem This could be optimized, but it's been typed for reading purpose.



Within this range (101..120), %D will always be between 0 and 19, which is the range of 20 we want. Added to MIN, it will range from 101 to 120...

As with the old vdsrnd32.dll, VDS v4.5 stick with the MIN <= rnd < MAX, even if it's not really well documented.

I'll be posting some other bugs I found in the bug report forum...

Greets to all!
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Bug Reports All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group