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 


Another way to create random numbers

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 3 Source Code
View previous topic :: View next topic  
Author Message
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2146
Location: A House

PostPosted: Mon Jan 14, 2002 8:24 am    Post subject: Another way to create random numbers Reply with quote

While I was working on some graphics for a web site, as usual, my mind
decided to wander off on something completely unrelated to the tasks at
hand. For some stupid reason, I pictured code for another way to
generate random numbers.....

Can someone please have me committed to the looney bin!!! Seeing
code constantly in one's mind has to be a sure sign of going insane!

Anyway, if anyone has any use for this code, enjoy it and have fun. Very Happy

____________________________________________________________________________________________________
Code:
REM --- Should work for VDS 2.x 3.x and 4.x

REM --- For a 1 digit random number
info @substr(@ext(@datetime()),@fsub(@len(@ext(@datetime())),0),@len(@ext(@datetime())))

REM --- For a 2 digit random number
info @substr(@ext(@datetime()),@fsub(@len(@ext(@datetime())),1),@len(@ext(@datetime())))

REM --- For a 3 digit random number
info @substr(@ext(@datetime()),@fsub(@len(@ext(@datetime())),2),@len(@ext(@datetime())))

REM --- For a 4 digit random number
info @substr(@ext(@datetime()),@fsub(@len(@ext(@datetime())),3),@len(@ext(@datetime())))

_________________
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
Necroprogramming FTW! - "Wait.. Is necroprogramming legal?"
http://www.freewarehome.com <-- Freeware listings since 1996
Back to top
View user's profile Send private message
Dr. Dread
Professional Member
Professional Member


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

PostPosted: Mon Jan 14, 2002 11:18 am    Post subject: Reply with quote

Nice thought, generating random numbers often comes in handy.

One comment, though: When run under a Windows version not using a point as decimal separator, you should add
Code:
OPTION DECIMALSEP,"."

to the code or else the @EXT function won't work.

Greetz
Dr. Dread
Back to top
View user's profile Send private message
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2146
Location: A House

PostPosted: Mon Jan 14, 2002 8:22 pm    Post subject: Reply with quote

Thanks Dread. I thought about that after I posted, but it was late,
and I was too tired to come back and mention that.
Wink

_________________
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
Necroprogramming FTW! - "Wait.. Is necroprogramming legal?"
http://www.freewarehome.com <-- Freeware listings since 1996
Back to top
View user's profile Send private message
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Mon Jan 14, 2002 9:51 pm    Post subject: Reply with quote

Hey Garrett,

Using @ext() on @datetime() is a nice idea. I usually checked for
the decimal point in the number instead (duh).

I have a question though:

I always put @datetime() into a var first and here's why: I'm
wondering, since the extension changes length, could the number
change while the computer is in the process of gettting the info
from one line where all the functions use @datetime()?

There are some other pitfalls to avoid, sometimes the number
will have very few digits, so it's best to check for length before
trying to get the substring. I sometimes use a REPEAT loop until
the number is valid (or between certain values, such as 2 and 8,
etc.).

Here's a simple example that uses one formula for different length
random numbers (notice when using 9 or 10, the number changes
less often because of the varying length of @datetime):
_______________________________________________________________________________________________________________________________________________________________________________________
Code:

OPTION SCALE, 96
OPTION DECIMALSEP, "."
TITLE By Mac
DIALOG CREATE,Test prog,-1,0,300,60
  DIALOG ADD,BUTTON,B1,5,5,100,30,"Choose Length"
  DIALOG ADD,BUTTON,B2,5,110,40,30,"Start"
  DIALOG ADD,STATUS,Stat
DIALOG SHOW

:EVLOOP
  WAIT EVENT
  goto @event()

:B1BUTTON
  %%length = @input(Enter number of digits for random number, 3)
  goto EVLOOP

:B2BUTTON
  if %%length
     REPEAT
       %r = @ext(@datetime())
       if @greater(@len(%r),%%length)
          DIALOG SET, STAT, @substr(%r, @succ(@diff(@len(%r), %%length)), @len(%r))
       end
       WAIT ".5"
       %e = @event()
     UNTIL %e
     goto %e
  end
  goto EVLOOP

:CLOSE
  EXIT

_________________
VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
Back to top
View user's profile Send private message Send e-mail
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2146
Location: A House

PostPosted: Wed Jan 16, 2002 2:42 am    Post subject: Reply with quote

Hi Mac,

Yeah, I had thought about adding the @datetime() to a var also, but tried
it this way first, and it worked fine. But there could be the potential that
maybe on a slow PC that time it takes might cause a problem. So it is
probably best to use a var instead of hard coding in the functions.

Also, instead of just using this for a random number itself, just using it
for the first 2 or 3 numbers for the seed to another random number
generator will be good.

While writing this, It's hitting me that there's so many ways that we can
make use of @ext(@datetime()) for random numbers. Such as taking
the var like you suggest, then adding a Wait "0.1", and then mulitply the
var by the current @ext(@datetime()). From there, extract what ever
amount of numbers you need from it, or do some more math functions
to it to randomize it even more.

I think with the use of this, the random number dll, one should be able
to continously get about as a random result as possible.

_________________
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
Necroprogramming FTW! - "Wait.. Is necroprogramming legal?"
http://www.freewarehome.com <-- Freeware listings since 1996
Back to top
View user's profile Send private message
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Wed Mar 12, 2003 6:39 pm    Post subject: Reply with quote

Here's a random example that's inclusive of %%min and
%%max, and is pretty fast if both have the same number
of digits. The @ask() function slows this working example
down quite a bit if it's not compiled though...
__________________________________________________________________________________________________________________________
Code:

:START
  %%min = 1000
  %%max = 9999

  rem -- The actual routine --
  REPEAT
    %r = @ext(@datetime())
    if @greater(@len(%r), @len(%%max))
       %n = @substr(%r, @succ(@diff(@len(%r), @len(%%max))), @len(%r))
    end
  UNTIL @both(@greater(%n, @pred(%%min)), @greater(@succ(%%max), %n))

  if @ask(Random = %n@cr()@cr()Continue?)
     goto START
  end
:CLOSE
  EXIT

Cheers, Mac Smile

_________________
VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
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 -> Visual DialogScript 3 Source Code 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