javascript generate random string
var crypto = require("crypto");
var id = crypto.randomBytes(20).toString('hex');
// "bb5dc8842ca31d4603d6aa11448d1654"
javascript generate random string
var crypto = require("crypto");
var id = crypto.randomBytes(20).toString('hex');
// "bb5dc8842ca31d4603d6aa11448d1654"
javascript get random string
function getRandomString(length) {
var randomChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var result = '';
for ( var i = 0; i < length; i++ ) {
result += randomChars.charAt(Math.floor(Math.random() * randomChars.length));
}
return result;
}
//usage: getRandomString(20); // pass desired length of random string
how to generate random character from an array js
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;
}
console.log(makeid());
js object random key
var randomProperty = function (obj) {
var keys = Object.keys(obj);
return obj[keys[ keys.length * Math.random() << 0]];
};
generate random key in javascript
<h6>Content 1:</h6>
<textarea class="content1" name="content1" id= "content1" spellcheck="false" onclick="content1()" readonly></textarea>
<h6>Content 2:</h6>
<input type="text" class="content2" name="content2" id= "content2" spellcheck="false" onclick="content1()" readonly>
<script>
var random_generator1 = document.getElementById('content1')
random_generator1.innerHTML = create_random_generator(10)
var random_generator2 = document.getElementById('content2')
random_generator2.innerHTML = create_random_generator(20)
function create_random_generator(string_length){
var random_string = ''
var char = 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ'
var i
for(i = 0; i < string_length; i++){
random_string = random_string + char.charAt(Math.floor(Math.random()* char.length))
}
return random_string
}
</script>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us