Hello !
I have a question about random integer from stream.
In all my project I am using a random integer in range from stream to get random integer, and the stream is made from time (using the milliseconds). I haven’t any problem before, it was working well.
But today, I was adding a function to my AI that is supposed to get a random integer and play a hit montage depending on this integer.
I have 4 hit montages, so I decide to get a random int between 0 and 3 and depending to this integer I get the hit montage from a data table.
Here is the function (I delete a part of the function and replace it by a print to be sure if it is working or not) :
After some test it appears that I always get number 1 and 2, never 0 and 3. I have done A LOT of test, more than hundred, maybe 200 ? And it is always 1 or 2.
So, it seems that my way to get number is not good… It is a bad news for because I did this to get number in all my project for a lot of things…
So, I did another test, I link to a keyboard key the previous code (not the function, just the code) and decide to test to see which number I could have. And surprise ! It works.
Why is it not working in my previous function, but working in an event like input action ? It is really strange. Is there a reason ? I have done more test, the fact that is it a function and an event is not the cause.
By the way, is this a bad idea to get random number as I am doing ? I now there is a lot of way to do it, but I thought this way was easy… Please tell me if it is a bad thing what I am doing.
Thank you a lot for your help and your time !
All the best,
Thomas
EDIT : another strange fact, I changed the value that was from 0 to 3, by 0 to 4 and then I manage to get random value from 0 to 3. But in the documentation, integer in range is supposed to get integer >= min and <= max, so the number 3 was supposed to be INCLUDE in the stream. Also, in my test with the input key, I was able to have number 3 without asking for number between 0 and 4.