How to get random different numbers in range
I'm having a little of a hard time finding the logic behind my problem, let's say i have a range that goes from 1 to N, how could i in blueprint pick a random quantity of integer numbers between 1 and N which are all different? Basically I need:
Pick a random quantity (1 <= Q <= N ) of random integer numbers ( 1 <= X <= N ) without X being repeated, all in blueprints.
asked Mar 13 '15 at 06:17 AM in Blueprint Scripting
You could fill an array of N size with numbers 1 through N, perform a shuffle on that array, then grab the first X elements.
answered Mar 13 '15 at 06:31 AM
Allar's suggestion is excellent for smaller ranges. That is how I would go about it for small values of N. For a larger N you might not want to create an array and shuffle the entire thing (say N is 100,000 or 1,000,000). Instead, if you need a large range, I would create a loop to add the random values to an array using the Add Unique node. That should prevent duplicates from showing up.
answered Mar 13 '15 at 03:54 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here