[ADD] Get Array Random element

Hello. Please add in blueprint function “get random array element”. I try make some function, but i cant make input Universal array, only with defend type.

make your own

Hey DCDenton,

CriErr has shown you the way to create a macro to work the way that you’ve requested. What you can do to call this macro or function at any time is to create either a Blueprint or a Macro Library. Here are a couple of links that’ll help you:

Blueprint Macro Library
Blueprint Macros and Macro Libraries
Making Macros
Macro Library UI

Thank you so much!!!

This will probably crash.
Your Max Index is (Length-1)

It won’t crash but will output None if the maximum value was output.

A macro like this one, not supposed to be fail-safe, also this one has a mistate, it should save random int as local int variable and use it as a source for outputs.

Works for me. Thanks for the info

Or even better just use “LastIndex” instead of length - 1, otherwise it won’t work if the array length is equal to 1.

That’s not true. If you were to get LastIndex on an array with a length of 1, you’d get the last index in the array.
But arrays start at an index of 0. So the index you’d get is 0.
Meaning, that if you do Length - 1, you’d end up with the correct index to reference that array element.

LastIndex == Array Length - 1

The only case I could see some funky behavior is if you have an array with empty indexes in between. Though I’m not certain of that.