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 help

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
tim6389
Professional Member
Professional Member


Joined: 01 Aug 2002
Posts: 790

PostPosted: Sat Jan 01, 2005 3:48 am    Post subject: @random help Reply with quote

hello all

yes i'am still around ...heheeh Smile anyways i have a dumb question i must be over looking something..when i uses the @random function it works fine BUT when i exit the program and re-start it it will start at the Beginning meaning this :

Code:

%h = @RANDOM(2,100)   
 
file copy, C:\test\test.exe, C:\test\%h.exe

info %h


if i start the program it will make a file called 2.exe now if I don't exit it.it will make random file name up to 100...how can i make it not all ways start at 2 without using a ini file? I hope ya follow what i mean here...

_________________
Have a nice day Smile
Back to top
View user's profile Send private message
jules
Professional Member
Professional Member


Joined: 14 Sep 2001
Posts: 1043
Location: Cumbria, UK

PostPosted: Sat Jan 01, 2005 11:59 am    Post subject: Reply with quote

The @random function always delivers the same series of numbers each time. This can be useful in many applications, for example when you are testing something and want to compare the results of one run of the program with another one.

If you want different results each time you have to use the RANDOM command to seed the random number generator with a different number each time. I usually use the date/time function for this, e.g. @datetime(hns).

_________________
The Tech Pro
www.tech-pro.net
Back to top
View user's profile Send private message Visit poster's website
tim6389
Professional Member
Professional Member


Joined: 01 Aug 2002
Posts: 790

PostPosted: Sat Jan 01, 2005 5:00 pm    Post subject: Reply with quote

ok, but will that start out the same when you first start the program? i know it does random just fine when the program is running and if you don't exit it...this is hard to explain

take my code i have posted above, run it in the vds ide don't complie it...now when you exit it and start it it will always start at 2 but if you don't exit it and just keep hitting the "run" it does random just fine...is there any way to make it so it will do random at start up?

thanks

_________________
Have a nice day Smile
Back to top
View user's profile Send private message
Hooligan
VDS Developer
VDS Developer


Joined: 28 Oct 2003
Posts: 480
Location: California

PostPosted: Sat Jan 01, 2005 5:23 pm    Post subject: Reply with quote

The @random() function is whats known as "pseudo-random"... Meaning it will always start with a "seed" and select the first number based on a very specific algorithm. Then it will select the second number using the same algorithm, and so on. This will result in a series of repeatable pseudo-random numbers, based on that "seed", (presumably zero, if you don't specify one). If you specified another seed (using the RANDOM command), it would create another series of repeatable pseudo-random numbers based on that seed. Therefore, using time to select the seed, would result in a different seed being selected to bases that particular instances' "series" of pseudo-random numbers on. Or at least a 1 in 82400 chance, if you used hours/minutes/seconds.

Hope this helps...
Hooligan

_________________
Hooligan

Why be normal?
Back to top
View user's profile Send private message
tim6389
Professional Member
Professional Member


Joined: 01 Aug 2002
Posts: 790

PostPosted: Sat Jan 01, 2005 5:56 pm    Post subject: Reply with quote

i understand what ya mean ( i think) but will i have to keep the vds program running to get random? or should i get random numbers when it start up for the first time? i'am trying to find out if i'am doing something wrong or is this normal?

thanks

_________________
Have a nice day Smile
Back to top
View user's profile Send private message
vtol
Valued Contributor
Valued Contributor


Joined: 05 Feb 2004
Posts: 656
Location: Eastern Indiana

PostPosted: Sat Jan 01, 2005 11:24 pm    Post subject: Reply with quote

Hi Tim

I prolly spent more time experimenting with Random than anyone - lol
I have your problem plus many more with Random, I tried everything and Random dont seem to work for me(you have to be there - like you said).
But Mac found me a work around that might work for you also, experiment with number shuffling instead of Random maybe.

GL
Back to top
View user's profile Send private message Visit poster's website
tim6389
Professional Member
Professional Member


Joined: 01 Aug 2002
Posts: 790

PostPosted: Sun Jan 02, 2005 12:51 am    Post subject: Reply with quote

vtol - if ya would can you share what mac should ya Smile or if mac's around i hope he will post Smile

thanks

_________________
Have a nice day Smile
Back to top
View user's profile Send private message
vtol
Valued Contributor
Valued Contributor


Joined: 05 Feb 2004
Posts: 656
Location: Eastern Indiana

PostPosted: Sun Jan 02, 2005 5:33 am    Post subject: Reply with quote

I posted a little random testing tool at 'VDS5 SourceCode' section...
Hope it helps you.
cheerios
Back to top
View user's profile Send private message Visit poster's website
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Sun Jan 02, 2005 6:17 am    Post subject: Reply with quote

tim,
Take a quicklook at the code below. I think it does what you want to do. It actually does it 2 different ways.

Code:

#DEFINE FUNCTION,TEMPFILENAME
Rem Since I don't have a test.exe lets make a file.
List create,1
List Add,1,ABCDEFGHIJKLMNOPQRSTUVWXYZ

Rem Here is your Seed based on hour, minute and second.
rem This will give you a more random number.
RANDOM @mod(@datetime(hmss),100)
rem This chooses a random number between 2 and 100 based on the seed
%h = @RANDOM(2,100)   
 
List SaveFile,1,C:\test\%h.exe
rem file copy, C:\test\test.exe, C:\test\%h.exe

info C:\test\%h.exe
REM you can do it like I did above or you can create unique file names
rem like all other Windows programs do see below.
%h = @TempFileName(c:\test,exe)
List SaveFile,1,%h
Info %h
Exit

:TEMPFILENAME
  %R =
  rem Load the Microsoft Visual C run time DLL.
  rem
  LoadLib msvcrt20.dll
  If %1
    Rem Change to the directory that we need to generate a unique name for
    directory change,%1
    rem Call the DLL's function called tmpname
    %T = @lib(msvcrt20,tmpnam,STR:,NIL:)
    If %2
      %R = %1\@SubStr(%T,2,@Pred(@len(%T))).%2
    Else
      %R = %1\@SubStr(%T,2,@Pred(@len(%T)))
    End
  Else
    rem Call the DLL's function called tmpname 
    %T = @lib(msvcrt20,tmpnam,STR:,NIL:)
    If %2
      %R = @SubStr(%T,2,@Pred(@len(%T))).%2
    Else
      %R = @SubStr(%T,2,@Pred(@len(%T)))
    End
  End   
  FreeLib msvcrt20
Exit %R


Well have fun let me know how it works for ya.

_________________
Home of

Give VDS a new purpose!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
tim6389
Professional Member
Professional Member


Joined: 01 Aug 2002
Posts: 790

PostPosted: Sun Jan 02, 2005 6:46 pm    Post subject: Reply with quote

vtol - i haven't looked at your yet Smile

dragonsphere - what you posted seems to work better then what i have i did some chnages to it and at least it don't start out with the same number however if you run it right after the program gets done it does make a pattern meaning this

5004.exe
5005.exe
5006.exe

in whick case i don't know if that part could be more random BUT its sure alot better then what i had...

thanks

here is what i have:
Code:

OPTION DECIMALSEP,.,
   %h = @RANDOM(@datetime(hhss),10000)
  file copy, C:\test\test1.exe, C:\test\%h.exe
  info C:\test\%h.exe
 exit



thanks guys

_________________
Have a nice day Smile
Back to top
View user's profile Send private message
jules
Professional Member
Professional Member


Joined: 14 Sep 2001
Posts: 1043
Location: Cumbria, UK

PostPosted: Mon Jan 03, 2005 12:35 pm    Post subject: Reply with quote

Perhaps I don't understand what you are trying to achieve, but I think you should be doing:

Code:
RANDOM @datetime(hns)


note: a command not a function, followed by:

Code:
%h = @random(10000)


Why exactly are you trying to create randomly named executable files, anyway?

_________________
The Tech Pro
www.tech-pro.net
Back to top
View user's profile Send private message Visit poster's website
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Mon Jan 03, 2005 2:17 pm    Post subject: Reply with quote

Tim,
You have to seed the Random number generator with the RANDOM command before you use the @RANDOM function just as Jules and I have suggested. We both used the @datetime function to seed it with a fairly unique number I modulated mine to match the min and max that you had originally choosen. Also if these are just temp files then just use the API that I suggested. The only issue with the API is for some reason when it is in a loop it does not generate a new unique name Sad So just use the combo of the RANDOM command to seed the generator and @RANDOM function to retrive the random number. This should work unless the clock on your PC is not working or you have fallen into some kind of space time warp Wink hehehehe.... Also the larger the max the more random and less likely the pattern will be repeated.

_________________
Home of

Give VDS a new purpose!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
tim6389
Professional Member
Professional Member


Joined: 01 Aug 2002
Posts: 790

PostPosted: Mon Jan 03, 2005 5:27 pm    Post subject: Reply with quote

dragonsphere - I see what you are say (i think) so i should uses this:
jules - i just pick exe for a example to show what the random is doing, i will be using it for making a ini file. I guess i could have used a ini in a example.. the reason why i want a random name is cuase the ini file will hold program data that i don't want the user to find easy..and if the user does find it . it wouldn't be the same file name on a other p.c..sorry i guess i should have say this before...

thanks


Code:

OPTION DECIMALSEP,.,
    RANDOM @datetime(hns)
  %h = @random(10000)
  file copy, C:\test\test1.exe, C:\test\%h.exe
  info C:\test\%h.exe
 exit


_________________
Have a nice day Smile
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: Tue Jan 04, 2005 6:16 am    Post subject: Reply with quote

If you want to generate random names that are hard to find, then don't stick with numbers only - they
could be fairly easy to spot if you sort folder contents.

Perhaps have a look here: http://forum.vdsworld.com/viewtopic.php?t=125
Doesn't even use RANDOM coz it's originally for VDS3, he-he

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
tim6389
Professional Member
Professional Member


Joined: 01 Aug 2002
Posts: 790

PostPosted: Thu Jan 06, 2005 2:01 am    Post subject: Reply with quote

Dr. Dread - thank you very much i like that better.....Smile




thanks to all that has help


tim

_________________
Have a nice day Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help 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