How to generate random code with limited range

selece28
Member Posts: 316
Hi Nav Masters
I have a problems, i need to generate 8 digit Code which each digit is random code consist of : number 2 to 9 (without 0 and 1) or A to Z or a to z
Can we do this?
How to do it in navision c/al code?
Thanks in advance,
I have a problems, i need to generate 8 digit Code which each digit is random code consist of : number 2 to 9 (without 0 and 1) or A to Z or a to z
Can we do this?
How to do it in navision c/al code?
Thanks in advance,
______________
Regards,
Steven
Regards,
Steven
0
Comments
-
RandomDigit is of type text. length 50
RandomDigit := CREATEGUID; RandomDigit := DELCHr(RandomDigit,'=','{}-01'); RandomDigit := copystr(RandomDigit,1,8); Message(RandomDigit)
0 -
You can also use
randomize;
RandomDigit := format(random(7)+2);
but the problem is that randomize needs a seed that is unique every time you call it.
otherwise it uses system time, and so if you call more than once within a second it will return the same value.0 -
Hi Rashed,
Thanks for the reply.
I think the 1st one is great, but what is the : CREATEGUID used for?
I don't understand, can you explain a little?
Ow and one more, random cannot randomize char right?
Thanks______________
Regards,
Steven0 -
ara3n wrote:RandomDigit is of type text. length 50
RandomDigit := CREATEGUID; RandomDigit := DELCHr(RandomDigit,'=','{}-01'); RandomDigit := copystr(RandomDigit,1,8); Message(RandomDigit)
=D> cool idea.David Singleton0 -
selece28 wrote:Hi Rashed,
Thanks for the reply.
I think the 1st one is great, but what is the : CREATEGUID used for?
I don't understand, can you explain a little?
CRATEGUID is generating GUID which is "Globally Unique Identifier". You can google more about that. It is some "code" which you can use as unique, because the chance, that somebody will generate same GUID on the planet is small. It means that the GUID is "random" and the code use this to generate random data and taking some character from the result as random...
Ow and one more, random cannot randomize char right?
Thanks
Char is just number presented as text. And because you can convert number to char and back, you can "randomize" char... Just random integer and assign it into Char variable...0 -
[Topic moved from Navision forum to Navision Tips & Tricks forum]Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
If you use the GIUD sugestion you may get unlucky and get a string with less then 8 characters if the GIUD generated containes less then 8 valid characters.
Instead create a character array that holds all the valid characters. Then generate 8 radom numbers between 1 and the length of the array and add the corresponding array element to your codestring.validChar[1]:='2'; validChar[2]:='3'; . . . validChar[7]:='9'; validChar[8]:='a'; validChar[9]:='b'; . . . validChar[32]:='z'; validChar[33]:='A'; validChar[34]:='B'; . . . validChar[57]:='Z'; codeString:=''; RANDOMIZE(); WHILE STRLENGTH(codeString)<8 DO BEGIN codeString:=codeString+validChar[RANDOM(57)]; END;
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions