Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
mobmsc2
Creator
Creator

How to randomly assign rows to be written out to csv files

Assume I have 4 inputs (input 1, 2,3 and 4) I need to create csv files which contain randomly selected rows from each input so that each row/record is only in 1 csv file and all rows/records are used. 

 

My initial thought is to find the number of rows in each input and select the smallest value (call it X). Using that I would assign a random number to each row in each input between 1 and X and then aggregate the rows by the random number. 


Anyone have any other ideas ?

 

I found this code for random numbers in this forum post which I hope could be reused to find the next int between 1 and X

 

java.util.Random (package)
// for generating random number for the range b\w 0000 to 9999
int randomInt = randomGenerator.nextInt(9999)
Labels (4)
3 Replies
Jesperrekuh
Specialist
Specialist

Add a (big) random value to each row, sort ascending and say you want max 100 records, simply limit on a row counter max value... I dont quite get the aggregate part?

If you get data from a database, example mysql, there is a: order by rand() limit 250
mobmsc2
Creator
Creator
Author

If a big random number was added to each of the 4 inputs and then the inputs merged before sorting wouldn't there be a possibility that 100 rows you write might not contain rows from each of the inputs?

Can you explain more about 

row counter

you mention? is it a component or a setting or code?

Jesperrekuh
Specialist
Specialist

I dont know your data distribution, however regarding a sample based on specific value look at pics and also added the job:

Note: wijk is dutch for area
0683p000009Lzh2.png0683p000009Lzh7.png0683p000009LzcX.png


examplejob_forversion_TOS_BD_v7.zip