# How I can generate random username with length 41 symbols

**URL:** <https://community.postman.com/t/how-i-can-generate-random-username-with-length-41-symbols/39706>\
**Category:** Help Hub\
**Tags:** random\
**Created:** [October 3, 2022, 8:15am UTC](https://community.postman.com/t/how-i-can-generate-random-username-with-length-41-symbols/39706 "2022-10-03T08:15:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anastasiiaka](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@anastasiiaka](https://community.postman.com/u/anastasiiaka)\
**Post date:** [October 3, 2022, 8:15am UTC](https://community.postman.com/t/how-i-can-generate-random-username-with-length-41-symbols/39706/1 "2022-10-03T08:15:54Z")

</div>

I need to generate random username and it must be 41 symbols length to check field ability

 ![Screenshot_76](https://us1.discourse-cdn.com/getpostman/original/3X/0/5/057a7c4b48f1ebef005fa4912247c38df52fb361.png)

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [October 3, 2022, 7:00pm UTC](https://community.postman.com/t/how-i-can-generate-random-username-with-length-41-symbols/39706/2 "2022-10-03T19:00:32Z")

</div>

Hi @anastasiiaka

Try adding this to your pre-req script;

```auto
function makeid(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));
   }
   pm.collectionVariables.set("username", result);
   return result;
}

console.log(makeid(41));

```

Original code;

> <https://stackoverflow.com/questions/1349404/generate-random-string-characters-in-javascript/1349426#1349426>
