Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

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.

Product Version: Not Selected
more ▼

asked Mar 13 '15 at 06:17 AM in Blueprint Scripting

avatar image

198 38 36 43

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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.

more ▼

answered Mar 13 '15 at 06:31 AM

avatar image

3.1k 51 119 487

avatar image DylanVelez Mar 13 '15 at 09:31 PM

Thanks, that suited my needs.

avatar image JakobR Apr 25 '16 at 12:18 PM

How exactly would this look in blueprint? The 'shuffle' node does only have an exec output and the 'GET' node an item node. How would I get an item after it has shuffled?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered Mar 13 '15 at 03:54 PM

avatar image

476 7 9 32

avatar image Allar Mar 13 '15 at 09:32 PM

Aye, this is definitely a better way to go for large values. I tend to not recommend this though because people sometimes create a bad source of random numbers and end up in occasional infinite loops. On the other hand, the above solution can be sped up in large cases by allocating space in the array ahead of time with a Resize node. I think the best possible solution would be to steal from cryptographic algorithims and use a seedable one way modulus generator as those functions are guaranteed to result in a unique and even distribution within a finite range

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question