# Blueprint: Random in Range but exclude "x"

Hey guys,
Here is what I am trying to do.
Return random integer from a range (0-10) but exclude a number (lets say 8) using blueprints.

None of the random blueprint node seem to do the trick. Any ideas guys?

Put your integers into array and random indice from that array and get value.

It is quite a unique case so I’m doubtful there is a built-in functionality. You may need to implement this yourself, along the lines of while the randomInt is equal to 8, get another random integer. I’m not sure about the best approach to this in blueprints however.

Dune,
That could still return 8 unless you could repeat until result =!. Which from what I know about blueprints we cannot do that. The closest thing I came up with in blueprints is:
rand(0-(8-1)) and rand((8+1)-10) and then randomly select between the two results.

This is not ideal so I am going to keep on digging.

Hey Pierdek, That is exactly what I would want:
array = (1,2,3,4,5,6,7,9,10)
rand(array)

Do you know away to create this is blueprints? Do we have the ability to write scripted nodes? I have tried using math expression node but to no avail.

You know what my issue was? I thought we didn’t have arrays as a variable type. I always thought that was strange, but then I learned you have to click the icon next to the variable type dropdown to make it an array.

Simple, but unclear.

Having an int array will allow me to do exactly what Pierdek suggested.
Thanks!

Put your integers into array and random indice from that array and get value.

Hello, not sure if this is the best solution since it requires a few variables and quite a few nodes, but I was thinking that this may help folks who stumble upon this old post.

In my example, I am using these integers to ensure that I play a different ambient noise track then I did previously.

As you can see here, I’ve created a random current variable. This is then checked against the previous value of ambiance (set at the end of the function) to determine if they are the same. This is also checked against the previous ambiance being the greatest value in the range. Now, this is where my design has a shortcoming: I simply have the value either increased by 1 if it is the same or reset if it is the same and also the maximum number of the range. While there is probably a simpler way, I simply used these boolean tests in two branchs and changed the value appropriately. This way, my ambient tracks will always be different!

I hope this helps anyone who is curious.

get random int from range
make a branch, check to see if the number is equal to the one you are trying to exclude
If it is, just make the pulse loop back and get a different number. If it is not, continue to the rest of your code

this is what im doing right now but after the first exclude I then need to exclude more and more

for example first time i get random number from 1-10 and store it in variable, then get random number from 1-10 and if this number is the one stored in the variable repeate process, the new result in new variable

next get a random number from 1-10 but if its equal to the number stored in varuable 1 or equal to variable 2 repeat.

and if I have to do this 500 times for random numbers from 1-1000 i will repeat the random integer node so often it may lag

I try find out what to do