SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    334
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript Code Generator

    I need to generate about 500, 8 character codes... Does anyone know of a JavaScript that can do this?

  2. #2
    SitePoint Addict jtrelfa's Avatar
    Join Date
    Oct 2004
    Location
    Troy, Mi
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you looking for random codes or something in particular?
    var me = null;

  3. #3
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    334
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yea just complete random codes, like 8gHgdf7n something like that...

  4. #4
    SitePoint Addict jtrelfa's Avatar
    Join Date
    Oct 2004
    Location
    Troy, Mi
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    untested...

    Code:
    function makeStrings() {
       var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
      var len = chars.length;
      var ret_val = [];
      for (var i = 0, i < 500; i++) {
        for(var j = 0; j < 8; j++) {
          ret_val[ret_val.length] = chars.charAt(Math.floor(Math.random() * len));
       }
      }
      return ret_val; //array of 500 codes
    }
    var me = null;


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •