New extension: Pseudo random
Description
Set seed to generate pseudo-random numbers in sub-events.
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 the extension
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:
- Create a new event with the condition "At the beginning of the scene" and the action "Set seed" and the seed equal to "1".
- Create a sub-event with the action "Log message" and the message "ToString(Random(100))+";"+ToString(Random(100))+";"+ToString(Random(100))".
- 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.
Checklist
- [x] I've followed all of the best practices.
- [x] I confirm that this extension can be integrated to this GitHub repository, distributed and MIT licensed.
- [x] I am aware that the extension may be updated by anyone, and do not need my explicit consent to do so.
What tier of review do you aim for your extension?
Community (Unreviewed)
Example file
Extension file
Extension by @Jurfix
You can update the extension on this "Pull Request" by commenting the update command: in the comment field, type !update, then drag and drop a zip file with your extension file in the commenting field, like how you initially submitted the extension. It should look like this:
!update [MyExtension.zip](https://github.com/GDevelopApp/GDevelop-extensions/files/12709661/MyExtension.zip)
It can take a few seconds for the file to fully upload and show as the above. Once it is like shown above, click "Comment" and let the bot do the rest!
Thank you for submitting an extension.
Extensions are meant to be editable by anyone. This means that:
- JavasScript code must not be minified (unless there is a technical reason)
- A link to the repository or topic must be included if any
!update PseudoRandomExtension.zip
✅ Successfully updated the extension.
Hi Davy @D8H, I replaced the minified library code with the non-minified one and added the repository link to the extension description, thanks.
- The link to the repository should be in a JS or event comment not in the description.
- Overriding
Mathfunction may lead to unexpected side effects. For instance, particle emitters or pitch randomization may useMath.rand. If VFX and SFX are disabled, could it mess with the reproducibility of the game run?
- Overriding function may lead to unexpected side effects. For instance, particle emitters or pitch randomization may use . If VFX and SFX are disabled, could it mess with the reproducibility of the game run?
Math``Math.rand
The Math.random() function is overridden only in the visibility zone after calling seedrandom(), that is, in the event where it is called and in subevents, in the rest of the game Math.random() works as before (randomly), usually I use it only once when starting a scene to build a level and the rest of the game works as before.
If VFX and SFX are disabled, could it mess with the reproducibility of the game run?
I didn't quite understand the question, but neither the sound reproduction nor the creation of particle emitters affected the game's reproductive ability.
!update PseudoRandomExtension.zip
❗ No updates found. Please check your file.
!update PseudoRandomExtension.zip
❗ No updates found. Please check your file.
!update PseudoRandomExtension.zip
✅ Successfully updated the extension.
I moved the repository link from the description to the js comment
Hi Davy @D8H, I updated the example by adding random value generation next to pseudo random values, this can also be combined into one event if necessary, but then it will be unclear when which sound plays PseudoRandomExample.zip
Yes, it can break certain processes in your game if you call "set seed" for the whole scene or the whole game, but you can easily control it by calling it only in one event (for example when starting a scene), that's why I set the extension category to "advanced", maybe a warning should be added, what do you think?
What do you do to enable it only for 1 event and its sub-events?
Just call the set seed function, in the event where it is called there will be a pseudo random, in all other events there will be a regular random
How does the extension make it works?
!update PseudoRandom.zip
Can't update the extension, as it doesn't pass automatic tests:
❌ 4 Errors found in extension 'PseudoRandom':
⟶ ❌ [Filled out names and descriptions]: Required field 'fullName' of the function 'BackRandom' is not filled out!
⟶ ❌ [Filled out names and descriptions]: Required field 'description' of the function 'BackRandom' is not filled out!
⟶ ❌ [Filled out names and descriptions]: Required field 'sentence' of the function 'BackRandom' is not filled out!
⟶ ❌ [JavaScript disallowed properties]: Found disallowed properties in extension 'PseudoRandom':
{
allowedProperties: [
'makeUuid', 'rgbToHex',
'rgbOrHexToRGBColor', 'rgbToHexNumber',
'hexNumberToRGB', 'hexToRGBColor',
'copyArray', 'staticArray',
'staticArray2', 'staticObject',
'toDegrees', 'toRad',
'random', 'randomFloat',
'randomFloatInRange', 'randomInRange',
'randomWithStep', 'evtTools',
'Variable', 'RuntimeObject',
'Logger'
],
disallowedProperty: '__PseudoRandomExtensionOriginalRandomFunction',
objectName: 'gdjs'
}
❌ 4 Errors found in extensions - please fix them before generating the registry.
I was wrong, it overrides the Math.random() function globally, not just in the event and sub-event, it seemed to me that this is because gdevelop itself returns the Math.random() function to its original form after some time (about a second). I added an action that overrides Math.random() to its original form forcibly, which must be called when the generation of values is complete, I have not spent time on the design of all this yet, I just want to know if this is a normal solution and whether it solves your concerns before I design it as needed, thanks.
To make this work only on one event and its sub-events, it should look like this:
I have not spent time on the design of all this yet, I just want to know if this is a normal solution and whether it solves your concerns before I design it as needed, thanks.
I would be more at ease with functions like NumberGenerator::Random() that don't have any side effect on standard libraries.
NumberGenerator::Random()
Then it won't be so clean, for each generation of one number you will need to have a unique seed, that is, each time after calling the generation you will have to add 1 to the seed, in my opinion this is extra work, if you use it as I showed in the last message, then there should be no side effects, since Math.random returns to its original form in the same frame
!update PseudoRandomExtension.zip
Can't update the extension, as it doesn't pass automatic tests:
❌ 1 Error found in extension 'PseudoRandom':
⟶ ❌ [JavaScript disallowed properties]: Found disallowed properties in extension 'PseudoRandom':
{
allowedProperties: [
'makeUuid', 'rgbToHex',
'rgbOrHexToRGBColor', 'rgbToHexNumber',
'hexNumberToRGB', 'hexToRGBColor',
'copyArray', 'staticArray',
'staticArray2', 'staticObject',
'toDegrees', 'toRad',
'random', 'randomFloat',
'randomFloatInRange', 'randomInRange',
'randomWithStep', 'evtTools',
'Variable', 'RuntimeObject',
'Logger'
],
disallowedProperty: '_PseudoRandom',
objectName: 'gdjs'
}
❌ 1 Error found in extensions - please fix it before generating the registry.
Hi @D8H , I updated the extension by removing the global override of Math.random() and replacing it with a local copy, and also added 5 expressions identical to the built-in random, only with pseudo random.
It works identically to the previous version, except that now you need to call expressions from the extension PseudoRandom::Random(), ... instead of the built-in ones.
I think this is a very useful and widely used thing, so I still expect to see it in this repository, thanks.
Updated example if needed, but everything should be intuitive, you don't even have to call "Set seed" if you don't call it then the default seed will be 1, and each call to the expression will return the next step of the randomness PseudoRandomExample.zip
The feature from this other PR could be integrated into your extension:
- https://github.com/GDevelopApp/GDevelop-extensions/pull/1602
It will add a new NormalRandom function that uses your pseudo Random function. I can add it at the end of the review if you want.
This Godot class has the same kind of features if you want to take some ideas from it: https://docs.godotengine.org/en/stable/classes/class_randomnumbergenerator.html