Skip to main content

All Questions

4 votes
3 answers
165 views

Efficiently generate a random position inside an outer rectangle but outside an inner rectangle

It should be a uniform distribution (ie: every point is equally as likely). I also don't want to use the simple solution of: "in a loop check to see if the current generated point is within the ...
Ryan Peschel's user avatar
3 votes
1 answer
204 views

Randomly set styles with JavaScript

I have created a function which randomly sets styles using CSS selectors. Right now it returns a random item from an array. The program also works with shorthand properties (such as ...
Gibberish's user avatar
  • 109
5 votes
1 answer
2k views

JavaScript random BigInt

Problem: JavaScript does not provide a random BigInt so there is a need to generate a random BigInt within a given range that is evenly distributed. Solution I have tried many algorithms with a ...
Blindman67's user avatar
  • 22.6k
3 votes
2 answers
649 views

Adding an 'enemy' to a game (with randomized properties)

I'm working on a game using the now abandoned Famo.us Javascript framework. I have the game in a running prototype and I'm building with Cordova and running it on an iPhone 6 using PhoneGap. There ...
RenaissanceProgrammer's user avatar
4 votes
2 answers
946 views

Normalized random position generator

I place various divs on screen by adding random x and y positions successively normalized with this function. My question is, how well is it written? Can I improve it? If so, then how? I am worried ...
Asperger's user avatar
  • 207
11 votes
2 answers
5k views

D&D dice rolling app

This JavaScript object is part of a mobile application that rolls dice for our D&D games. Here are some example of possible inputs from the user: 2d4 2d4 + 3d6 2d4 + 3d6 + 12 ...
IEatBagels's user avatar
  • 12.5k
3 votes
2 answers
2k views

Generating a random number of progress bars

I have this JSFiddle that generates a random number of progress bars then assigns a random number and percent to them. I am wondering if you know how to better optimize this code to have better run-...
Roger's user avatar
  • 133
11 votes
2 answers
191 views

Random weighted 'tick' function

This is a very simple function, but it gets run on a roughly 10ms interval, so I'm looking for ways to improve it. The first obvious thing is that it has to run the comparisons nearly every time as it ...
njp's user avatar
  • 383
10 votes
2 answers
677 views

Can this secure, random generator be improved?

This random generator uses cryptographically secure numbers/chars instead of Math.random(). The Javascript code with jQuery works well but I affect clean code ;) It ...
John's user avatar
  • 101
3 votes
1 answer
1k views

Dice notation roller in JavaScript

I have the following function, intended to take standard dice notation (XdY+Z) and return a (sort of) random number based on the input. Are there any bugs/bad ideas/optimizable sections I am missing? ...
Hydrothermal's user avatar
8 votes
3 answers
3k views

Improve random password generator

Can you please take a look at my code and improve it (if necessary)? http://jsfiddle.net/U6R6E/ Javascript (with jQuery) ...
Maximilian Fuchs's user avatar
0 votes
2 answers
9k views

Randomize a jQuery object list

Well this was a simplest code competition at my work. I tried a couple things, they accepted but none of them is I wanted. Because both are always giving same result. I tried to randomize like this <...
siniradam's user avatar
  • 119
3 votes
1 answer
4k views

JavaScript: Weighted Random Generator

I'm attempting to create a function that will give me a "fish" at random, though a bias random depending on the weight value for the "fish". ...
Shaz's user avatar
  • 135