{"record":{"id":"6446a2bfe75defda","repo":"phaserjs/phaser","slug":"invalid-random-format","errorCode":null,"errorMessage":"invalid random() format","messagePattern":"invalid random\\(\\) format","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/tweens/builders/GetValueOp.js","lineNumber":159,"sourceCode":"\n                if (isRandom)\n                {\n                    getEnd = function ()\n                    {\n                        return FloatBetween(value1, value2);\n                    };\n                }\n                else\n                {\n                    getEnd = function ()\n                    {\n                        return Between(value1, value2);\n                    };\n                }\n            }\n            else\n            {\n                throw new Error('invalid random() format');\n            }\n        }\n        else\n        {\n            op = op[0];\n            var num = parseFloat(propertyValue.substr(2));\n\n            switch (op)\n            {\n                case '+':\n                    getEnd = function (target, key, value)\n                    {\n                        return value + num;\n                    };\n                    break;\n\n                case '-':\n                    getEnd = function (target, key, value)","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/phaserjs/phaser/blob/41be1e462bc600064e498cba370bfa8c5c055a22/src/tweens/builders/GetValueOp.js#L141-L177","documentation":"Thrown by Phaser.Tweens.Builders.GetValueOp when a tween property value is a string starting with 'random' or 'int' but the parenthesis/comma syntax is malformed. The parser requires all three of '(', ')', and ',' to be present (via indexOf truthiness) to split the two numeric bounds. If any delimiter is missing, or if the indexOf check returns a falsy value, Phaser cannot build the getEnd function and aborts. The valid forms are `random(min, max)` for a float and `int(min, max)` for an integer.","triggerScenarios":"Passing props like `{ x: 'random(10,100)' }` works, but `{ x: 'random(10 100)' }` (missing comma), `{ x: 'random 10, 100' }` (missing parens), `{ x: 'int(10)' }` (missing comma), or `{ x: 'random(10,100' }` (missing close paren) all throw. Also triggered by typos such as `radom(...)` that happen to still start with the checked prefix in a future revision, or non-ASCII punctuation (full-width comma/parens) copied from rich text.","commonSituations":"Authoring tween props in a data file or editor that strips/normalizes punctuation. Copy-pasting example strings from a blog that uses smart quotes or en-dashes. Localizing a config where a translator replaced the comma. Using a template literal that injects undefined for one bound: `\\`random(${min},${max})\\`` with min/max undefined still parses but a missing template expression can drop the comma.","solutions":["Use the exact form: 'random(min, max)' or 'int(min, max)' with ASCII comma and parentheses, no spaces inside required but both delimiters mandatory.","If the bounds are dynamic, prefer a function: props: { x: (target, key, value) => Phaser.Math.FloatBetween(min, max) } which avoids string parsing entirely.","Sanitize/normalize the string before passing it: replace smart quotes and full-width commas with ASCII equivalents.","Log the offending propertyValue right before the tween to confirm its exact characters."],"exampleFix":"// before\nthis.tweens.add({ targets: sprite, x: 'random(10 100)', duration: 1000 });\n\n// after\nthis.tweens.add({ targets: sprite, x: 'random(10, 100)', duration: 1000 });\n// or, safer with dynamic values:\nthis.tweens.add({ targets: sprite, x: () => Phaser.Math.FloatBetween(10, 100), duration: 1000 });","handlingStrategy":"validation","validationCode":"function isValidRandomString(str) {\n  if (typeof str !== 'string') return true; // not a random string at all\n  var lower = str.toLowerCase();\n  if (!(lower.startsWith('random') || lower.startsWith('int'))) return true;\n  return lower.indexOf('(') > 0 && lower.indexOf(')') > 0 && lower.indexOf(',') > 0;\n}","typeGuard":"function isTweenableValue(v) {\n  if (typeof v === 'number' || typeof v === 'function') return true;\n  if (Array.isArray(v)) return true;\n  if (typeof v === 'string') {\n    var op = v.toLowerCase();\n    if (op.startsWith('random') || op.startsWith('int')) {\n      return op.indexOf('(') > 0 && op.indexOf(')') > 0 && op.indexOf(',') > 0;\n    }\n    return ['+=', '-=', '*=', '/='].some(function (p) { return op.startsWith(p); });\n  }\n  return false;\n}","tryCatchPattern":"try {\n  this.tweens.add({ targets: obj, props: { x: raw }, duration: 1000 });\n} catch (e) {\n  if (e.message === 'invalid random() format') {\n    this.tweens.add({ targets: obj, props: { x: () => Phaser.Math.FloatBetween(10, 100) }, duration: 1000 });\n  } else { throw e; }\n}","preventionTips":["For dynamic bounds, use a function value instead of a 'random(min,max)' string to bypass the parser.","When authoring tween props from data, validate strings match /^random\\(\\s*-?\\d+(\\.\\d+)?\\s*,\\s*-?\\d+(\\.\\d+)?\\s*\\)$/i.","Normalize smart quotes and full-width punctuation in localized config files.","Unit-test tween configs that use random/int syntax."],"tags":["tween","parser","string-format","random","syntax"],"backgroundTag":null,"analyzedSha":"41be1e462bc600064e498cba370bfa8c5c055a22","analyzedAt":"2026-08-13T04:23:39.729Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}