Duplicates Within Random Array
I have created an array of props then spawn onto a conveyor belt in a random order.
Everything is working as intended, however i do not wish duplicate props to spawn. How can i go about doing this?
I am using the 'random integer' function, which does serve the purpose of the random side but i cannot see an option for avoiding duplicates.
asked Apr 17 '16 at 02:18 PM in Blueprint Scripting
an easy way would be saving the already created generated Numbers in an Array. Then iterate through the Array every time you create a new random number and check if you already had that number. If yes, generate a new random number, if not, use it:
answered Apr 17 '16 at 06:35 PM
Your RNG saved my life!
Probably a better way of naming posts, something like a standard of some kind would be awesome. This was really hard to find even though I was looking for this exact thing for 6 hours...
answered Apr 24 '18 at 09:21 PM
Here is a simple function that will de-duplicate an array (of vectors in my case but the idea is the same for other types).
We clear WorkArray straight away, in case data got left in there somehow.
We use a ForEachLoop to iterate through each item in RawArray (our input variable) and IF that item is not yet in WorkArray we Add that item into WorkArray
After we are done iterating, we Return Node, making sure to plug WorkArray into the CleanedArray slot on the Return Node.
answered May 25 '18 at 11:35 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here