Random Range

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
cangri
Newbie
Posts: 7
Joined: Sun May 29, 2005 6:26 pm

Random Range

Post by cangri » Sat Jun 04, 2005 7:46 pm

How can i set the random> range like this 1<= to <X?

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Sun Jun 05, 2005 3:56 am

I think range for random always starts at zero, so you could send range to (X-1) and add 1 to the result of random.

If you want random numbers from 1 to 25

Random>24,randnum
Add>randnum,1

User avatar
tony_smith
Pro Scripter
Posts: 70
Joined: Wed May 14, 2003 8:25 pm
Location: Vancouver BC Canada

Post by tony_smith » Mon Aug 29, 2005 9:00 pm

I was browsing for a solution and this topic gave me an idea to solve my problem. I needed to create a file name containing the year, month, day and a random 4-character number. Problem is that if I used 9999 as a range, I would get anything from 0 to 9999. This is what I dreamed up; probably not that elegant, but it works...

Year>the_year
Month>the_month
Day>the_day
Random>9,RNBR1
Random>9,RNBR2
Random>9,RNBR3
Random>9,RNBR4
Let>RNBR=%RNBR1%%RNBR2%%RNBR3%%RNBR4%
Let>file=MMAWP%the_year%%the_month%%the_day%%RNBR%.edi

Hope this helps someone.

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Mon Aug 29, 2005 9:20 pm

Hi,

What about this:

Random>9999,r
Let>r=000%r%
Let>r={copy("%r%",length("%r%")-3,4)}
MJT Net Support
[email protected]

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Aug 30, 2005 3:02 am

Nothing better than a ShowOff! :D

I like it...... thinking outside the box.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
tony_smith
Pro Scripter
Posts: 70
Joined: Wed May 14, 2003 8:25 pm
Location: Vancouver BC Canada

Post by tony_smith » Tue Sep 06, 2005 4:26 pm

Wow... That is a nice, tight bit of code.

But... how does MS resolve that? I can see what it does, but I have no idea how it does it...

Let>r={copy("%r%",length("%r%")-3,4)}


What is the code after Let>r= ? Is it some boolean logic? How can I learn more about how to use this and related techniques?

T

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Tue Sep 06, 2005 4:52 pm

That Copy command is hiding under Complex Expressions in the manual
function Copy(S: string; Index, Count: Integer): string
The Copy function returns a substring of a string. S is a string-type expression. Index and Count are integer-type expressions. Copy returns a string containing Count characters starting at S[Index]. If Index is larger than the length of S, Copy returns an empty string. If Count specifies more characters than are available, the only the characters from S[Index] to the end of S are returned.
String = %r%
Index = length of the r string - 3
Count = gimme 4 characters

Because the index is calculated as length -3 then the 4 characters will always be the last 4 characters of the r string.

User avatar
tony_smith
Pro Scripter
Posts: 70
Joined: Wed May 14, 2003 8:25 pm
Location: Vancouver BC Canada

Post by tony_smith » Tue Sep 06, 2005 4:58 pm

Har! Begad... it was there all the time. Many thanks for steering me there.

-T
(Somewhere directly above the centre of the planet)

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts