Add random string of letters and numbers to a filename

Javascript renaming examples. Javascript renaming is supported in version 3 or newer.

Add random string of letters and numbers to a filename

Postby SaladGoat » Mon Jul 02, 2018 7:11 pm

Would be cool to be able to add a random string of letters and numbers to a filename, or to replace the name with such.
Thanks!
SaladGoat
 
Posts: 2
Joined: Mon Jul 02, 2018 7:05 pm

Re: random string

Postby therube » Mon Jul 02, 2018 9:06 pm

I'd suspect that JavaScript rename part of the program could do that already.https://www.google.com/search?q=javascript+randomize+name&rls=org.mozilla:en-US:unofficial
therube
 
Posts: 922
Joined: Mon Jan 18, 2016 6:23 pm

Re: random string

Postby Admin » Tue Jul 03, 2018 5:13 am

Yes, something like this, in BRU javacript:

Code: Select all
function makeid() {
  var text = "";
  var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

  for (var i = 0; i < 5; i++)
    text += possible.charAt(Math.floor(Math.random() * possible.length));

  return text;
}

newName = name + makeid();
Admin
Site Admin
 
Posts: 1896
Joined: Tue Mar 08, 2005 8:39 pm


Return to Javascript Renaming