That is, how evenly distributed are the probabilities of each number? The actual quality of the generator itself. There are three major factors that can affect the end result: I have to mention it because this method is potentially bad (please, before you open Godot and make it generate thousands and thousands of numbers, measuring the resulting distribution, just to tell I'm wrong here, read the entire topic). Random Number And Distributionīefore going into any random selection I have to talk about the method typically used to keep a randomly generated integer number in the desired range, which is the modulus ( %) operator, which in code is some_value = rand() % some_range. I also suggest reading this official Godot documentation tutorial on how to use its random number generator, which also include some use case examples. However, if you want to see the technique in action I do have a demo in my Godot Addon Pack (more specifically the Inventory System demo) that do use it. Note that for this specific tutorial I do not present any reference source code on Github simply because I don't think there is any need for it. After that I present some tips on how to use this technique on a few possible different use cases. First I go over a tiny bit of theory then show the implementation in Godot using GDScript. In this tutorial I show a method to randomly select something from a list but taking weights (different probabilities) into account. When working in a game we frequently want to randomly select something, be it to generate loot or maybe pick a random tile to generate levels.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |