Trying to randomly get a data table row, but it's acting insane [Solved]

Simply, I’m getting the number of rows. From 1 to the number of rows, I’m generating a random integer. I try to look up a row by that number, but it never gets the rows right. See the pictures for reference.

Where is it going wrong? If anyone could help, I’d appreciate it.
Thanks

In this first picture you are getting the length of the rows, then outputting a random index of it. You need to use a Get (for array) to get the entry at that index.

EDIT: Ignore the red errors, but you have some options:


(If you use random from stream, you will need to feed something into that)

Thanks for your quick response. I first tried the second example, but I couldn’t find the random node. Then I tried your third example, but it’s also producing odd results. Here is my visual code:

Here is the output from the example.

That is not quite option 3. To get the random node, drag off the array output and it will come up in search.
I’m certain why it’s off, but I would add a print string between the GetDataTableRowNames to see what is piped into the row name that follows.

I don’t know what you mean when you said I didn’t try option 3. But I took a picture to prove that nothing comes up when I type in random with context checked. Unchecking it didn’t help.

I did what you suggested and put in a print string before I got the row by name. I also tried having it print the number of rows it found, which was 12.

The third picture shows every time I hit V. The first time I hit V was “Row name to get: 9”, followed by “Item name: Clothes” and “Integer: 6”.

But as you can see, it’s still not behaving as intended.

Well this helps. Sorry to see that random does not show up, that’s very strange.

The way random nodes work is they are fetched at the time it is called, this is why they are different. But I don’t see a pattern either, so yeah, it’s not working correctly.

One thing to add to this mix is the ways I posted above which differ from what you have. When we get the length of an array, it returns how many are in it, in this case 12. When we Get from an array, we are looking at the index which starts at 0. If the random range is 1-12, it will fail if 12 is fetched because there is no index 12. If you use GetRandomInteger instead of the range version, it will automatically compensate for this problem. To get the proper range, it would need to be Array Length -1 as the max and 0 as the min. This is what GetRandomInteger does as well as the other methods.

EDIT: In blueprint speak, and since random isn’t showing up, these work to the same capacity - bottom one is close to what you have:

1 Like

Thank you very much for your help! I set the random int in a variable, so it would be the same each time through. It’s working correctly now. Here’s what I have now.


Thanks again! :grin:

1 Like

Yes! Great, I totally forget to mention that, but yes, setting as a variable will definitely do the trick!