Tuesday, August 27, 2019

How to generate random string and charaters in Angular

Today I will show you a trick in Angular programming language in particular and programming languages In general, it is generate random string and charaters in Angular, to realize this problem, you really understand and want it, you just need to do it as follows:

You execute a handler function to look up a string random.
  private randomString(length) {
    var result           = '';
    var characters       = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    var charactersLength = characters.length;
    for ( var i = 0; i < length; i++ ) {
       result += characters.charAt(Math.floor(Math.random() * charactersLength));
    }
    return result;
 }
Next you attach a string or output the string to test
 console.log(this.randomString(100));
 Tags: How to generate random string, generate random string and number, generate random string in angular, angular random string

No comments:

Post a Comment