Question

Select a random value from a csv file, but only the same value once.?

  • 29 December 2017
  • 2 replies
  • 7 views

I have a list of numbers from 1 to 100. I want every time I run the workspace that a random number is selected. But it must not be the same no. Before you have been through the entire list. I use the selected number to retrieve some specific information from a particular row in another table where Rowid equals the number.

I do not think I've found a transformer that can do this.


2 replies

Badge +2

Hi,

Did you tried "sampler"?

Userlevel 4
Badge +25

Quick and dirty option:

You'll need to use a RandomNumberGenerator within a loop. Check the randomly generated number against a set of numbers that were previously selected, if there's a match loop and do a new random number, if there's no match store that number in the set of previous ones and pull that row from the table.

However, if you get near the end (i.e. you've got 100 numbers to select from and you've done say 90 of them already you might end up looping a long time (theoretically indefinitely even).

So maybe another approach... Let's say the table you want to randomly read from is table_1. If your list of numbers remains static generate a random number for each of them, sort by that number, store in a new table (table_2) and on every workspace run pull the first record from table_2, read the original number and pull that row from table_1, then remove that record from table_2.

No looping involved and you know for certain each record in table_1 can't be read more than once.

Reply