Quick javascript help

Oblivion13

Regular Member
Joined
Sep 7, 2011
Messages
480
Reaction score
260
I have a script that does random numbers. It only does 5 numbers right now. (like - w4hty)

I am trying to have it do numbers like this

2jsnf-csjxm-cnjc2-fucns-cnash

Like how it does 5 then - then 5 more. I need a total of 25 characters.

Can anyone help me with this?

Here is the code I have for getting just the 5

Code:
 <script>
      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;
      }
      
      document.getElementById("uniqueID").innerHTML = makeid();
    </script>
 
Code:
<script>
    function makeid(){
        var text = "";
        var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        for( var x=0; x < 5; x++ ){
            for( var i=0; i < 5; i++ ){
                text += possible.charAt(Math.floor(Math.random() * possible.length));
            }
            if (x < 4){
                text += "-";
            }
        }
        return text;
    }
    document.getElementById("uniqueID").innerHTML = makeid();
</script>

Output for example : HKmiH-VJkHt-jF3ES-04AUH-jx6lI
 
Hi ombrocapelo;

It's a great logic which is the best idea to use it. What will you do? - To build such logic? Sometimes, it's more difficult to build such logic. Can you share some idea to build such quick logic?
 
Back
Top