Languages
[Edit]
EN

JavaScript - random bytes

10 points
Created by:
Adnaan-Robin
334

In this short article, we would like to show how using JavaScript, draw some random bytes array.

Practical example:

// ONLINE-RUNNER:browser;

const randomBytes = (count) => {
	const result = Array(count);
  	for (let i = 0; i < count; ++i) {
    	result[i] = Math.floor(256 * Math.random());
    }
  	return result;
};


// Usage example:

const a = randomBytes(5);
const b = randomBytes(10);
const c = randomBytes(15);

console.log(JSON.stringify(a));  // [55,114,30,83,96]
console.log(JSON.stringify(b));  // [42,26,254,43,30,14,179,4,214,72]
console.log(JSON.stringify(c));  // [238,203,230,91,223,161,59,10,105,200,45,145,64,145,210]
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join