Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 22nd, 2024, 5:46 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Specific code generator
PostPosted: January 10th, 2014, 1:53 pm 
Offline

Joined: July 5th, 2011, 2:51 pm
Posts: 44
Opus: Opus Pro 8
OS: Windows 10; 64-bit operating system
System: Intel(R) Core(TM) i5 CPU, 4.00GB (RAM)
Hi! I am not sure if this is the right section to post this, but I am sure my issue would require some scripting..

Alright.. this is what I want to do.

Create a small app that generates a random 8 character code starting with a specific number or text. The code must consist of these first 3 characters "14k" and then 2 random letters, followed by 3 random numbers.

So it would look something like this: "14kth837"

Also, I want the app to save the codes that were already generated on a text doc so that they are not re-used.

Is there a method to do this?

Thanks


For this message Animellarx has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Specific code generator
PostPosted: January 10th, 2014, 2:29 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Yes, there are probably several ways of doing this:


The numbers can be generated using:

Code:
var Nx = String.random(10) //returns any number up to, but not including 10


The function above could also be used to generate an ASCII value and converted to it's corresponding character.
http://www.asciitable.com/

Code:
var Lx = String.fromCharCode(65);  //65 would return the letter A


The whole lot can then be concatenated:

Code:
myCode = "14kth" + L1 + L2 + N1 + N2 + N3


Once you got that bit working, you'd then need to look at reading and writing to a text file. Depending on the number of these 'codes' generated though - that might be convoluted.

mack
https://twitter.com/imsmackavi

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


For this message mackavi has been thanked by : Animellarx


Top
 Profile Visit website  
 
 Post subject: Re: Specific code generator
PostPosted: January 15th, 2014, 1:52 pm 
Offline

Joined: July 5th, 2011, 2:51 pm
Posts: 44
Opus: Opus Pro 8
OS: Windows 10; 64-bit operating system
System: Intel(R) Core(TM) i5 CPU, 4.00GB (RAM)
Can you explain this in more detail please? I am not too familiar with the string.charcode...

Thanks :)


For this message Animellarx has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Specific code generator
PostPosted: January 15th, 2014, 4:23 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Just put all the code in a script object and preview the page:

Code:
myLetter = generateRandomLetter()

Debug.trace("You generated the letter "+myLetter+'\n\n');


//Generate a string of random letters

myString = "";

for (var i = 0; i < 10;i++){

   myString = myString + generateRandomLetter()
   }

Debug.trace("You generated the string - "+ myString+'\n\n')






function generateRandomLetter(){

n =  String.random(26); //  pick a number from 0 - 25

n = n + 65; //converts random into an ascii number for uppercase.

/*
---------------------WHY?------------------------------------

if n = 0 then n + 65 = 65 which is the ascii code for 'A'
if n = 25 then n + 65 = 90 which is the ascii code for 'Z'

ASCII codes here:
http://www.asciitable.com/
*/

l = String.fromCharCode(n) //the function changes the value in n to a letter by matching it to the corresponding ASCII code.
return l;
}


mack
https://twitter.com/imsmackavi

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


For this message mackavi has been thanked by : Animellarx


Top
 Profile Visit website  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot] and 23 guests


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 post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group