Skip to content
Advertisement

Tag: random

Random alpha-numeric string in JavaScript?

What’s the shortest way (within reason) to generate a random alpha-numeric (uppercase, lowercase, and numbers) string in JavaScript to use as a probably-unique identifier? Answer If you only want to allow specific characters, you could also do it like this: Here’s a jsfiddle to demonstrate: http://jsfiddle.net/wSQBx/ Another way to do it could be to use a special string that tells

Create an array with random values

How can I create an array with 40 elements, with random values from 0 to 39 ? Like I tried using solutions from here: http://freewebdesigntutorials.com/javaScriptTutorials/jsArrayObject/randomizeArrayElements.htm but the array I get is very little randomized. It generates a lot of blocks of successive numbers… Answer Here’s a solution that shuffles a list of unique numbers (no repeats, ever). If you want

Write a truly inclusive random method for javascript

Javascript’s MATH object has a random method that returns from the set [0,1) 0 inclusive, 1 exclusive. Is there a way to return a truly random method that includes 1. e.g. While this always returns a number from the set [0,1] it is not truly random. Answer To put it bluntly, what you’re trying to do doesn’t make sense. Remember

Advertisement