🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!
I have these five array variables and I want to pick each one by random without picking it back twice or more.
How do I achieve this? Thanks in advance.
If you want to be able to use this data again without overwriting it then first clone it into a new array and work with that array; if you don't care about losing the data you can just work with x directly.
Randomize a number R from 1-N. N is initially 5 (the total available to be randomly picked), but will be reduced later
Do whatever you want with x[R]
Replace x[R] with x[N] (swap it into its position)
Reduce N by 1
Repeat
If you just want to keep using that same array instead of cloning you can also use the [InitialN + 1]th index (or the [0]th index) to temporarily store x[R] before overwriting it:
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.