[ANSWERED] Random Accessing Text through Data Array
-
I have a couple of thousand word text that I want to pull in and randomly access individual words. I'm trying to figure out how the data array actor works and if that is the best method. Watched the Guru session, and it seems I should be able to what I'm trying to there but have been running into the basic problem of making an Excel file that will separate the words into individual cells in Excel (did that by doing text into columns/space) but then the file needs to be exported as Tab Delimited, and looking more closely it seems that the final file needs to be in a .txt format? which I'm stymied by as well. So perhaps there is a post out there already on how to do this, or if if another actor set-up would work better if I could be directed there? Thanks much.
-
@montana said:
I have a couple of thousand word text that I want to pull in and randomly access individual words. I'm trying to figure out how the data array actor works and if that is the best method.
The best method depends on how random you want to be. Do you want a completely random word from anywhere in the file? Do you want to allow repeats? (If you don't want repeats, the Shuffle actor will be helpful.)
Personally, I'd pull in the entire text with a File Reader or Read Text From File actor, then use Javascript to find out how many words are in the file, feed that max number into a Shuffle actor so I could use the Shuffle actor for randomization, then use Javascript again to take the number from the Shuffle actor and use it to select a the corresponding word from the text. If you literally just have a text file and want to be able to hit a trigger and get a random word from it, that's dead easy (if you have the right Javascript User Actors).
File download for all of the Scenes in the screenshots below: select-random-word-2025-01-27-4.0.7.izz
Read Text From File:
File Reader (I prefer Read Text From File because of the greater degree of control it offers, but File Reader is much simpler):
Data Array can work, but it's just a bit trickier since you need to hardcode some logic to deal with the dynamic nature of randomized text (blank text, allowing the same slot to be used twice in a row, etc.)
@montana said:
it seems I should be able to what I'm trying to there but have been running into the basic problem of making an Excel file that will separate the words into individual cells in Excel (did that by doing text into columns/space) but then the file needs to be exported as Tab Delimited, and looking more closely it seems that the final file needs to be in a .txt format? which I'm stymied by as well.
If you go into Excel and do File > Save As > File Format > Specialty Formats, one of the options is a text file that's tab-delimited. Excel and do File > Save As > File Format > Specialty Formats, one of the options is a text file that's tab-delimited.
So perhaps there is a post out there already on how to do this, or if if another actor set-up would work better if I could be directed there?
There might be other posts if you search "random text", "random string", or "random", but the frontrunner actors are File Reader (but you'll need some Javascript), Read Text from File (but you'll need some Javascript), Data Array (a bit trickier, but do-able), and of course there's also the Pythoner actor (but for that you either need to be able to write Python code or be very patient with an machine learning tool like ChatGPT.)
-
Thanks as ever for your prompt and thorough feedback! Read Text from File works fine for what I need. I'll get into the other two patches in the next days and see what they're about. All the best from Montana