mirror of
https://github.com/webodf/WebODF.git
synced 2026-12-01 16:56:05 +01:00
* Supports multiple instances in the same doc * Able to exercise entire selection controller * Can say meow (and other text manipulation actions) * Knows about undo & redo * Will also destroy your document formatting too! * Can cut, copy & paste * Bella is a tidy cat and likes valid documents * Bella can be hooked up to use an existing cursor * Custom actions to be loaded externally * Has AMD integration * Add checks to ensure the cursor is in a valid step. Issue highlighted in review of PR #451. * Add a seeded random number generator to allow reproduction of crashes. Original source: https://github.com/davidbau/seedrandom * Add some really simple reporting stats * Allow seed to be specified via URL Major features ============== Add an "auto drive" feature (the cat herder) Auto drive will automatically cycle the page after the specified number of pounces. If an unhandled exception occurs, it will PUT a file to the server in the same location that contains the number of pounces that happened, and the original seed, along with the error information. Notes ===== * Limit how frequently document length checks are performed * Using a real SessionController causes problems with double-events
53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
define("webodf/plugins/bella/Random", ["./seedrandom"], function(seedrandom) {
|
|
"use strict";
|
|
|
|
function Random(seed) {
|
|
var random = new seedrandom(seed);
|
|
|
|
/**
|
|
* Return a random number between min (included) & max (excluded)
|
|
* @param {number=} min
|
|
* @param {number=} max
|
|
* @returns {!number}
|
|
*/
|
|
function getInt(min, max) {
|
|
min = min === undefined ? Number.MIN_VALUE : min;
|
|
max = max === undefined ? Number.MAX_VALUE : max;
|
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
|
|
// Also http://stackoverflow.com/questions/1527803/generating-random-numbers-in-javascript-in-a-specific-range
|
|
return Math.floor(random() * (max - min) + min);
|
|
}
|
|
|
|
this.getInt = getInt;
|
|
|
|
function getBool() {
|
|
return random() < .5;
|
|
}
|
|
|
|
this.getBool = getBool;
|
|
|
|
function getElement(list) {
|
|
var index = getInt(0, list.length);
|
|
return list[index];
|
|
}
|
|
|
|
this.getElement = getElement;
|
|
|
|
function popListElement(list) {
|
|
var index = getInt(0, list.length),
|
|
item = list[index];
|
|
list.splice(index, -1);
|
|
return item;
|
|
}
|
|
|
|
this.popListElement = popListElement;
|
|
|
|
function oneIn(chance) {
|
|
return getInt(0, chance) === 0;
|
|
}
|
|
|
|
this.oneIn = oneIn;
|
|
}
|
|
|
|
return Random;
|
|
}); |