Random Range
Moderators: JRL, Dorian (MJT support)
Random Range
How can i set the random> range like this 1<= to <X?
- tony_smith
- Pro Scripter
- Posts: 70
- Joined: Wed May 14, 2003 8:25 pm
- Location: Vancouver BC Canada
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.
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.
Hi,
What about this:
Random>9999,r
Let>r=000%r%
Let>r={copy("%r%",length("%r%")-3,4)}
What about this:
Random>9999,r
Let>r=000%r%
Let>r={copy("%r%",length("%r%")-3,4)}
MJT Net Support
[email protected]
[email protected]
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
- tony_smith
- Pro Scripter
- Posts: 70
- Joined: Wed May 14, 2003 8:25 pm
- Location: Vancouver BC Canada
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
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
-
- Automation Wizard
- Posts: 1101
- Joined: Fri Jan 07, 2005 5:55 pm
- Location: Somewhere else on the planet
That Copy command is hiding under Complex Expressions in the manual
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.
String = %r%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.
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.
- tony_smith
- Pro Scripter
- Posts: 70
- Joined: Wed May 14, 2003 8:25 pm
- Location: Vancouver BC Canada