From d4cd583c0d68e249b954d3bdb96267ff21456d0b Mon Sep 17 00:00:00 2001 From: Jurfix Date: Sat, 5 Apr 2025 22:32:43 +0000 Subject: [PATCH 1/4] Automated Extension submission for issue #1644 --- extensions/community/PseudoRandom.json | 87 ++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 extensions/community/PseudoRandom.json diff --git a/extensions/community/PseudoRandom.json b/extensions/community/PseudoRandom.json new file mode 100644 index 000000000..377e4d3d2 --- /dev/null +++ b/extensions/community/PseudoRandom.json @@ -0,0 +1,87 @@ +{ + "author": "", + "category": "Advanced", + "extensionNamespace": "", + "fullName": "Pseudo random", + "gdevelopVersion": "", + "helpPath": "", + "iconUrl": "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0ibWRpLXNlZWQtb3V0bGluZSIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiB2aWV3Qm94PSIwIDAgMjQgMjQiPjxwYXRoIGQ9Ik0xNy4yLDVWNUMxNy44LDUgMTguNCw1IDE4LjksNS4xQzE5LjEsNy40IDE5LjEsMTIgMTYuNCwxNS4yQzE0LjQsMTcuNyAxMSwxOSA2LjQsMTlDNiwxOSA1LjUsMTkgNS4xLDE5QzQuOSwxNC40IDUuOCwxMC44IDcuOSw4LjVDMTAuNCw1LjYgMTQuNCw1IDE3LjIsNU0xNy4yLDNDMTEuNywzIDEuNiw1LjEgMy4yLDIwLjhDNC4zLDIwLjkgNS40LDIxIDYuNCwyMUMyNC4zLDIxIDIwLjcsMy4zIDIwLjcsMy4zQzIwLjcsMy4zIDE5LjMsMyAxNy4yLDNNMTcsN0M3LDcgNywxNyA3LDE3QzExLDkgMTcsNyAxNyw3WiIgLz48L3N2Zz4=", + "name": "PseudoRandom", + "previewIconUrl": "https://asset-resources.gdevelop.io/public-resources/Icons/2a6e6d587c6bdcd43a56925d77bd4a7d96a3a1132e9a0dc0ce324d0858971990_seed-outline.svg", + "shortDescription": "Set seed to generate pseudo-random numbers in sub-events.", + "version": "1.0.0", + "description": [ + "This extension will be useful for:", + "- Re-creating a randomly generated level.", + "- Debugging everything related to randomness in your game.", + "- Use in multiplayer so that all players have the same random event without having to synchronize its components.", + "", + "How to use:", + "- Put the action \"Set seed\" with a specific seed in the form of a number, for example \"1\", then all expressions and conditions of randomness in subevents will give the same result (each expression and condition separately) until you change the seed, meaning the expressions Random(), RandomInRange, RandomFloat() etc. and the condition \"Pick a random instance\".", + "", + "Example:", + "1. Create a new event with the condition \"At the beginning of the scene\" and the action \"Set seed\" and the seed equal to \"1\".", + "2. Create a sub-event with the action \"Log message\" and the message \"ToString(Random(100))+\";\"+ToString(Random(100))+\";\"+ToString(Random(100))\".", + "3. Look in the console and you will see that the result at each restart will be equal to \"17;21;53\" until you change the seed." + ], + "tags": [ + "random", + "seed", + "pseudo", + "generation" + ], + "authorIds": [ + "dt0tRnf2kHWJnjkrpnzTzNj9Yc63" + ], + "dependencies": [], + "globalVariables": [], + "sceneVariables": [], + "eventsFunctions": [ + { + "fullName": "", + "functionType": "Action", + "name": "onFirstSceneLoaded", + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::JsCode", + "inlineCode": "!function(a,b){var l,c=eval(\"this\"),d=256,g=\"random\",h=b.pow(d,6),i=b.pow(2,52),j=2*i,k=d-1;function m(r,t,e){var u=[],f=q(function n(r,t){var e,o=[],i=typeof r;if(t&&\"object\"==i)for(e in r)try{o.push(n(r[e],t-1))}catch(n){}return o.length?o:\"string\"==i?r:r+\"\\0\"}((t=1==t?{entropy:!0}:t||{}).entropy?[r,s(a)]:null==r?function(){try{var n;return l&&(n=l.randomBytes)?n=n(d):(n=new Uint8Array(d),(c.crypto||c.msCrypto).getRandomValues(n)),s(n)}catch(n){var r=c.navigator,t=r&&r.plugins;return[+new Date,c,t,c.screen,s(a)]}}():r,3),u),p=new n(u),m=function(){for(var n=p.g(6),r=h,t=0;n>>=1;return(n+t)/r};return m.int32=function(){return 0|p.g(4)},m.quick=function(){return p.g(4)/4294967296},m.double=m,q(s(p.S),a),(t.pass||e||function(n,r,t,e){return e&&(e.S&&o(e,p),n.state=function(){return o(p,{})}),t?(b[g]=n,r):n})(m,f,\"global\"in t?t.global:this==b,t.state)}function n(n){var r,t=n.length,u=this,e=0,o=u.i=u.j=0,i=u.S=[];for(t||(n=[t++]);e Date: Sun, 6 Apr 2025 13:02:55 +0000 Subject: [PATCH 2/4] Updated extension --- extensions/community/PseudoRandom.json | 257 ++++++++++++++++++++++++- 1 file changed, 253 insertions(+), 4 deletions(-) diff --git a/extensions/community/PseudoRandom.json b/extensions/community/PseudoRandom.json index 377e4d3d2..16fcd57a1 100644 --- a/extensions/community/PseudoRandom.json +++ b/extensions/community/PseudoRandom.json @@ -9,7 +9,7 @@ "name": "PseudoRandom", "previewIconUrl": "https://asset-resources.gdevelop.io/public-resources/Icons/2a6e6d587c6bdcd43a56925d77bd4a7d96a3a1132e9a0dc0ce324d0858971990_seed-outline.svg", "shortDescription": "Set seed to generate pseudo-random numbers in sub-events.", - "version": "1.0.0", + "version": "1.0.1", "description": [ "This extension will be useful for:", "- Re-creating a randomly generated level.", @@ -22,13 +22,17 @@ "Example:", "1. Create a new event with the condition \"At the beginning of the scene\" and the action \"Set seed\" and the seed equal to \"1\".", "2. Create a sub-event with the action \"Log message\" and the message \"ToString(Random(100))+\";\"+ToString(Random(100))+\";\"+ToString(Random(100))\".", - "3. Look in the console and you will see that the result at each restart will be equal to \"17;21;53\" until you change the seed." + "3. Look in the console and you will see that the result at each restart will be equal to \"17;21;53\" until you change the seed.", + "", + "This extension uses the \"seedrandom.js\" library:", + "- https://github.com/davidbau/seedrandom" ], "tags": [ "random", "seed", "pseudo", - "generation" + "generation", + "procedual" ], "authorIds": [ "dt0tRnf2kHWJnjkrpnzTzNj9Yc63" @@ -45,7 +49,252 @@ "events": [ { "type": "BuiltinCommonInstructions::JsCode", - "inlineCode": "!function(a,b){var l,c=eval(\"this\"),d=256,g=\"random\",h=b.pow(d,6),i=b.pow(2,52),j=2*i,k=d-1;function m(r,t,e){var u=[],f=q(function n(r,t){var e,o=[],i=typeof r;if(t&&\"object\"==i)for(e in r)try{o.push(n(r[e],t-1))}catch(n){}return o.length?o:\"string\"==i?r:r+\"\\0\"}((t=1==t?{entropy:!0}:t||{}).entropy?[r,s(a)]:null==r?function(){try{var n;return l&&(n=l.randomBytes)?n=n(d):(n=new Uint8Array(d),(c.crypto||c.msCrypto).getRandomValues(n)),s(n)}catch(n){var r=c.navigator,t=r&&r.plugins;return[+new Date,c,t,c.screen,s(a)]}}():r,3),u),p=new n(u),m=function(){for(var n=p.g(6),r=h,t=0;n>>=1;return(n+t)/r};return m.int32=function(){return 0|p.g(4)},m.quick=function(){return p.g(4)/4294967296},m.double=m,q(s(p.S),a),(t.pass||e||function(n,r,t,e){return e&&(e.S&&o(e,p),n.state=function(){return o(p,{})}),t?(b[g]=n,r):n})(m,f,\"global\"in t?t.global:this==b,t.state)}function n(n){var r,t=n.length,u=this,e=0,o=u.i=u.j=0,i=u.S=[];for(t||(n=[t++]);e= overflow) { // To avoid rounding up, before adding\r", + " n /= 2; // last byte, shift everything\r", + " d /= 2; // right using integer math until\r", + " x >>>= 1; // we have exactly the desired bits.\r", + " }\r", + " return (n + x) / d; // Form the number within [0, 1).\r", + " };\r", + "\r", + " prng.int32 = function() { return arc4.g(4) | 0; }\r", + " prng.quick = function() { return arc4.g(4) / 0x100000000; }\r", + " prng.double = prng;\r", + "\r", + " // Mix the randomness into accumulated entropy.\r", + " mixkey(tostring(arc4.S), pool);\r", + "\r", + " // Calling convention: what to return as a function of prng, seed, is_math.\r", + " return (options.pass || callback ||\r", + " function(prng, seed, is_math_call, state) {\r", + " if (state) {\r", + " // Load the arc4 state from the given state if it has an S array.\r", + " if (state.S) { copy(state, arc4); }\r", + " // Only provide the .state method if requested via options.state.\r", + " prng.state = function() { return copy(arc4, {}); }\r", + " }\r", + "\r", + " // If called as a method of Math (Math.seedrandom()), mutate\r", + " // Math.random because that is how seedrandom.js has worked since v1.0.\r", + " if (is_math_call) { math[rngname] = prng; return seed; }\r", + "\r", + " // Otherwise, it is a newer calling convention, so return the\r", + " // prng directly.\r", + " else return prng;\r", + " })(\r", + " prng,\r", + " shortseed,\r", + " 'global' in options ? options.global : (this == math),\r", + " options.state);\r", + "}\r", + "\r", + "//\r", + "// ARC4\r", + "//\r", + "// An ARC4 implementation. The constructor takes a key in the form of\r", + "// an array of at most (width) integers that should be 0 <= x < (width).\r", + "//\r", + "// The g(count) method returns a pseudorandom integer that concatenates\r", + "// the next (count) outputs from ARC4. Its return value is a number x\r", + "// that is in the range 0 <= x < (width ^ count).\r", + "//\r", + "function ARC4(key) {\r", + " var t, keylen = key.length,\r", + " me = this, i = 0, j = me.i = me.j = 0, s = me.S = [];\r", + "\r", + " // The empty key [] is treated as [0].\r", + " if (!keylen) { key = [keylen++]; }\r", + "\r", + " // Set up S using the standard key scheduling algorithm.\r", + " while (i < width) {\r", + " s[i] = i++;\r", + " }\r", + " for (i = 0; i < width; i++) {\r", + " s[i] = s[j = mask & (j + key[i % keylen] + (t = s[i]))];\r", + " s[j] = t;\r", + " }\r", + "\r", + " // The \"g\" method returns the next (count) outputs as one number.\r", + " (me.g = function(count) {\r", + " // Using instance members instead of closure state nearly doubles speed.\r", + " var t, r = 0,\r", + " i = me.i, j = me.j, s = me.S;\r", + " while (count--) {\r", + " t = s[i = mask & (i + 1)];\r", + " r = r * width + s[mask & ((s[i] = s[j = mask & (j + t)]) + (s[j] = t))];\r", + " }\r", + " me.i = i; me.j = j;\r", + " return r;\r", + " // For robust unpredictability, the function call below automatically\r", + " // discards an initial batch of values. This is called RC4-drop[256].\r", + " // See http://google.com/search?q=rsa+fluhrer+response&btnI\r", + " })(width);\r", + "}\r", + "\r", + "//\r", + "// copy()\r", + "// Copies internal state of ARC4 to or from a plain object.\r", + "//\r", + "function copy(f, t) {\r", + " t.i = f.i;\r", + " t.j = f.j;\r", + " t.S = f.S.slice();\r", + " return t;\r", + "};\r", + "\r", + "//\r", + "// flatten()\r", + "// Converts an object tree to nested arrays of strings.\r", + "//\r", + "function flatten(obj, depth) {\r", + " var result = [], typ = (typeof obj), prop;\r", + " if (depth && typ == 'object') {\r", + " for (prop in obj) {\r", + " try { result.push(flatten(obj[prop], depth - 1)); } catch (e) {}\r", + " }\r", + " }\r", + " return (result.length ? result : typ == 'string' ? obj : obj + '\\0');\r", + "}\r", + "\r", + "//\r", + "// mixkey()\r", + "// Mixes a string seed into a key that is an array of integers, and\r", + "// returns a shortened string seed that is equivalent to the result key.\r", + "//\r", + "function mixkey(seed, key) {\r", + " var stringseed = seed + '', smear, j = 0;\r", + " while (j < stringseed.length) {\r", + " key[mask & j] =\r", + " mask & ((smear ^= key[mask & j] * 19) + stringseed.charCodeAt(j++));\r", + " }\r", + " return tostring(key);\r", + "}\r", + "\r", + "//\r", + "// autoseed()\r", + "// Returns an object for autoseeding, using window.crypto and Node crypto\r", + "// module if available.\r", + "//\r", + "function autoseed() {\r", + " try {\r", + " var out;\r", + " if (nodecrypto && (out = nodecrypto.randomBytes)) {\r", + " // The use of 'out' to remember randomBytes makes tight minified code.\r", + " out = out(width);\r", + " } else {\r", + " out = new Uint8Array(width);\r", + " (global.crypto || global.msCrypto).getRandomValues(out);\r", + " }\r", + " return tostring(out);\r", + " } catch (e) {\r", + " var browser = global.navigator,\r", + " plugins = browser && browser.plugins;\r", + " return [+new Date, global, plugins, global.screen, tostring(pool)];\r", + " }\r", + "}\r", + "\r", + "//\r", + "// tostring()\r", + "// Converts an array of charcodes to a string\r", + "//\r", + "function tostring(a) {\r", + " return String.fromCharCode.apply(0, a);\r", + "}\r", + "\r", + "//\r", + "// When seedrandom.js is loaded, we immediately mix a few bits\r", + "// from the built-in RNG into the entropy pool. Because we do\r", + "// not want to interfere with deterministic PRNG state later,\r", + "// seedrandom will not call math.random on its own again after\r", + "// initialization.\r", + "//\r", + "mixkey(math.random(), pool);\r", + "\r", + "//\r", + "// Nodejs and AMD support: export the implementation as a module using\r", + "// either convention.\r", + "//\r", + "\r", + "// When included as a plain script, set up Math.seedrandom global.\r", + "math['seed' + rngname] = seedrandom;\r", + "\r", + "// End anonymous scope, and pass initial values.\r", + "})(\r", + " // global: `self` in browsers (including strict mode and web workers),\r", + " // otherwise `this` in Node and other environments\r", + " (typeof self !== 'undefined') ? self : this,\r", + " [], // pool: entropy pool starts empty\r", + " Math // math: package containing random, pow, and seedrandom\r", + ");\r", + "" + ], "parameterObjects": "", "useStrict": true, "eventsSheetExpanded": false From c963818ff9d5d601ef81eef8912d6cb3d2cb9372 Mon Sep 17 00:00:00 2001 From: Jurfix Date: Sun, 6 Apr 2025 16:59:02 +0000 Subject: [PATCH 3/4] Updated extension --- extensions/community/PseudoRandom.json | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/extensions/community/PseudoRandom.json b/extensions/community/PseudoRandom.json index 16fcd57a1..6957ef211 100644 --- a/extensions/community/PseudoRandom.json +++ b/extensions/community/PseudoRandom.json @@ -9,7 +9,7 @@ "name": "PseudoRandom", "previewIconUrl": "https://asset-resources.gdevelop.io/public-resources/Icons/2a6e6d587c6bdcd43a56925d77bd4a7d96a3a1132e9a0dc0ce324d0858971990_seed-outline.svg", "shortDescription": "Set seed to generate pseudo-random numbers in sub-events.", - "version": "1.0.1", + "version": "1.0.2", "description": [ "This extension will be useful for:", "- Re-creating a randomly generated level.", @@ -22,10 +22,7 @@ "Example:", "1. Create a new event with the condition \"At the beginning of the scene\" and the action \"Set seed\" and the seed equal to \"1\".", "2. Create a sub-event with the action \"Log message\" and the message \"ToString(Random(100))+\";\"+ToString(Random(100))+\";\"+ToString(Random(100))\".", - "3. Look in the console and you will see that the result at each restart will be equal to \"17;21;53\" until you change the seed.", - "", - "This extension uses the \"seedrandom.js\" library:", - "- https://github.com/davidbau/seedrandom" + "3. Look in the console and you will see that the result at each restart will be equal to \"17;21;53\" until you change the seed." ], "tags": [ "random", @@ -50,6 +47,7 @@ { "type": "BuiltinCommonInstructions::JsCode", "inlineCode": [ + "// Source: https://github.com/davidbau/seedrandom\r", "/*\r", "Copyright 2019 David Bau.\r", "\r", From 7af9b0a52e21e62cf84e9c88216eaad1d9f3a3de Mon Sep 17 00:00:00 2001 From: Jurfix Date: Tue, 12 Aug 2025 20:10:31 +0000 Subject: [PATCH 4/4] Updated extension --- extensions/community/PseudoRandom.json | 274 ++++++++++++++++++++++++- 1 file changed, 266 insertions(+), 8 deletions(-) diff --git a/extensions/community/PseudoRandom.json b/extensions/community/PseudoRandom.json index 6957ef211..66196e2cc 100644 --- a/extensions/community/PseudoRandom.json +++ b/extensions/community/PseudoRandom.json @@ -8,8 +8,8 @@ "iconUrl": "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0ibWRpLXNlZWQtb3V0bGluZSIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiB2aWV3Qm94PSIwIDAgMjQgMjQiPjxwYXRoIGQ9Ik0xNy4yLDVWNUMxNy44LDUgMTguNCw1IDE4LjksNS4xQzE5LjEsNy40IDE5LjEsMTIgMTYuNCwxNS4yQzE0LjQsMTcuNyAxMSwxOSA2LjQsMTlDNiwxOSA1LjUsMTkgNS4xLDE5QzQuOSwxNC40IDUuOCwxMC44IDcuOSw4LjVDMTAuNCw1LjYgMTQuNCw1IDE3LjIsNU0xNy4yLDNDMTEuNywzIDEuNiw1LjEgMy4yLDIwLjhDNC4zLDIwLjkgNS40LDIxIDYuNCwyMUMyNC4zLDIxIDIwLjcsMy4zIDIwLjcsMy4zQzIwLjcsMy4zIDE5LjMsMyAxNy4yLDNNMTcsN0M3LDcgNywxNyA3LDE3QzExLDkgMTcsNyAxNyw3WiIgLz48L3N2Zz4=", "name": "PseudoRandom", "previewIconUrl": "https://asset-resources.gdevelop.io/public-resources/Icons/2a6e6d587c6bdcd43a56925d77bd4a7d96a3a1132e9a0dc0ce324d0858971990_seed-outline.svg", - "shortDescription": "Set seed to generate pseudo-random numbers in sub-events.", - "version": "1.0.2", + "shortDescription": "Pseudo random number generator based on seed.", + "version": "2.1.0", "description": [ "This extension will be useful for:", "- Re-creating a randomly generated level.", @@ -17,11 +17,11 @@ "- Use in multiplayer so that all players have the same random event without having to synchronize its components.", "", "How to use:", - "- Put the action \"Set seed\" with a specific seed in the form of a number, for example \"1\", then all expressions and conditions of randomness in subevents will give the same result (each expression and condition separately) until you change the seed, meaning the expressions Random(), RandomInRange, RandomFloat() etc. and the condition \"Pick a random instance\".", + "- Put the action \"Set seed\" with a specific seed in the form of a number, for example \"1\", after that use expressions from this extension, they will return the same numbers every restart until you change the seed.", "", "Example:", "1. Create a new event with the condition \"At the beginning of the scene\" and the action \"Set seed\" and the seed equal to \"1\".", - "2. Create a sub-event with the action \"Log message\" and the message \"ToString(Random(100))+\";\"+ToString(Random(100))+\";\"+ToString(Random(100))\".", + "2. Create a sub-event with the action \"Log message\" and the message \"ToString(PseudoRandom::Random(100))+\";\"+ToString(PseudoRandom::Random(100))+\";\"+ToString(PseudoRandom::Random(100))\".", "3. Look in the console and you will see that the result at each restart will be equal to \"17;21;53\" until you change the seed." ], "tags": [ @@ -291,28 +291,52 @@ " [], // pool: entropy pool starts empty\r", " Math // math: package containing random, pow, and seedrandom\r", ");\r", + "\r", "" ], "parameterObjects": "", "useStrict": true, "eventsSheetExpanded": false + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "PseudoRandom::SetSeed" + }, + "parameters": [ + "", + "Time(\"timestamp\")", + "0", + "" + ] + } + ] } ], "parameters": [], "objectGroups": [] }, { - "description": "Set seed to generate pseudo-random numbers in sub-events.", + "description": "Set seed for pseudo random number generator.", "fullName": "Set seed", "functionType": "Action", "name": "SetSeed", - "sentence": "Set seed to _PARAM1_", + "sentence": "Set seed to _PARAM1_ with initial step _PARAM2_", "events": [ { "type": "BuiltinCommonInstructions::JsCode", "inlineCode": [ - "const seed = eventsFunctionContext.getArgument(\"Seed\");", - "Math.seedrandom(seed);" + "gdjs.__PseudoRandomExtension = {};\r", + "gdjs.__PseudoRandomExtension.seed = eventsFunctionContext.getArgument(\"Seed\");\r", + "gdjs.__PseudoRandomExtension.rng = new Math.seedrandom(gdjs.__PseudoRandomExtension.seed);\r", + "gdjs.__PseudoRandomExtension.step = eventsFunctionContext.getArgument(\"Step\");\r", + "\r", + "for (let i = 0; i < gdjs.__PseudoRandomExtension.step; i++) {\r", + " gdjs.__PseudoRandomExtension.rng();\r", + "}" ], "parameterObjects": "", "useStrict": true, @@ -324,6 +348,240 @@ "description": "Seed", "name": "Seed", "type": "expression" + }, + { + "description": "Start generation at a certain step", + "name": "Step", + "type": "expression" + } + ], + "objectGroups": [] + }, + { + "description": "Returns the last generation step.", + "fullName": "Step", + "functionType": "Expression", + "name": "Step", + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::JsCode", + "inlineCode": "eventsFunctionContext.returnValue = gdjs.__PseudoRandomExtension.step;", + "parameterObjects": "", + "useStrict": true, + "eventsSheetExpanded": false + } + ], + "expressionType": { + "type": "expression" + }, + "parameters": [], + "objectGroups": [] + }, + { + "description": "Returns the last used seed.", + "fullName": "Seed", + "functionType": "Expression", + "name": "Seed", + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::JsCode", + "inlineCode": "eventsFunctionContext.returnValue = gdjs.__PseudoRandomExtension.seed;", + "parameterObjects": "", + "useStrict": true, + "eventsSheetExpanded": false + } + ], + "expressionType": { + "type": "expression" + }, + "parameters": [], + "objectGroups": [] + }, + { + "description": "Pseudo random integer.", + "fullName": "Pseudo random integer", + "functionType": "Expression", + "name": "Random", + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::JsCode", + "inlineCode": [ + "const max = eventsFunctionContext.getArgument(\"Max\");\r", + "\r", + "eventsFunctionContext.returnValue = Math.floor(gdjs.__PseudoRandomExtension.rng() * (max + 1));\r", + "gdjs.__PseudoRandomExtension.step++;" + ], + "parameterObjects": "", + "useStrict": true, + "eventsSheetExpanded": false + } + ], + "expressionType": { + "type": "expression" + }, + "parameters": [ + { + "description": "Maximum value", + "name": "Max", + "type": "expression" + } + ], + "objectGroups": [] + }, + { + "description": "Pseudo random integer in range.", + "fullName": "Pseudo random integer in range", + "functionType": "Expression", + "name": "RandomInRange", + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::JsCode", + "inlineCode": [ + "const max = eventsFunctionContext.getArgument(\"Max\");", + "const min = eventsFunctionContext.getArgument(\"Min\");", + "", + "eventsFunctionContext.returnValue = Math.floor(gdjs.__PseudoRandomExtension.rng() * (max - min + 1)) + min;", + "gdjs.__PseudoRandomExtension.step++;" + ], + "parameterObjects": "", + "useStrict": true, + "eventsSheetExpanded": false + } + ], + "expressionType": { + "type": "expression" + }, + "parameters": [ + { + "description": "Minimum value", + "name": "Min", + "type": "expression" + }, + { + "description": "Maximum value", + "name": "Max", + "type": "expression" + } + ], + "objectGroups": [] + }, + { + "description": "Pseudo random float.", + "fullName": "Pseudo random float", + "functionType": "Expression", + "name": "RandomFloat", + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::JsCode", + "inlineCode": [ + "const max = eventsFunctionContext.getArgument(\"Max\");\r", + "\r", + "eventsFunctionContext.returnValue = gdjs.__PseudoRandomExtension.rng() * max;\r", + "gdjs.__PseudoRandomExtension.step++;" + ], + "parameterObjects": "", + "useStrict": true, + "eventsSheetExpanded": false + } + ], + "expressionType": { + "type": "expression" + }, + "parameters": [ + { + "description": "Maximum value", + "name": "Max", + "type": "expression" + } + ], + "objectGroups": [] + }, + { + "description": "Pseudo random float in range.", + "fullName": "Pseudo random float in range", + "functionType": "Expression", + "name": "RandomFloatInRange", + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::JsCode", + "inlineCode": [ + "const max = eventsFunctionContext.getArgument(\"Max\");", + "const min = eventsFunctionContext.getArgument(\"Min\");", + "", + "eventsFunctionContext.returnValue = gdjs.__PseudoRandomExtension.rng() * (max - min) + min;", + "gdjs.__PseudoRandomExtension.step++;" + ], + "parameterObjects": "", + "useStrict": true, + "eventsSheetExpanded": false + } + ], + "expressionType": { + "type": "expression" + }, + "parameters": [ + { + "description": "Minimum value", + "name": "Min", + "type": "expression" + }, + { + "description": "Maximum value", + "name": "Max", + "type": "expression" + } + ], + "objectGroups": [] + }, + { + "description": "Pseudo random integer in steps.", + "fullName": "Pseudo random integer in steps", + "functionType": "Expression", + "name": "RandomWithStep", + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::JsCode", + "inlineCode": [ + "const max = eventsFunctionContext.getArgument(\"Max\");", + "const min = eventsFunctionContext.getArgument(\"Min\");", + "const step = eventsFunctionContext.getArgument(\"Step\");", + "", + "const range = Math.floor((max - min) / step) + 1;", + "const randomStepIndex = Math.floor(gdjs.__PseudoRandomExtension.rng() * range);", + "", + "eventsFunctionContext.returnValue = min + randomStepIndex * step;", + "gdjs.__PseudoRandomExtension.step++;" + ], + "parameterObjects": "", + "useStrict": true, + "eventsSheetExpanded": false + } + ], + "expressionType": { + "type": "expression" + }, + "parameters": [ + { + "description": "Minimum value", + "name": "Min", + "type": "expression" + }, + { + "description": "Maximum value", + "name": "Max", + "type": "expression" + }, + { + "description": "Step", + "name": "Step", + "type": "expression" } ], "objectGroups": []