Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I want to generate 20 random numbers to be distributed within 100%.
I am using the below script but it is creating some duplicates. Please advice on getting the unique 20 records
Table:
LOAD
ROUND(rand()*20,1)AS User_Number,
'10' AS Percentage
AutoGenerate 2;
Concatenate(Table)
LOAD
ROUND(rand()*20,1)AS User_Number,
'15' AS Percentage
AutoGenerate 3;
Concatenate(Table)
LOAD
ROUND(rand()*20,1)AS User_Number,
'20' AS Percentage
AutoGenerate 4;
Concatenate(Table)
LOAD
ROUND(rand()*20,1)AS User_Number,
'25' AS Percentage
AutoGenerate 5;
Concatenate(Table)
LOAD
ROUND(rand()*20,1)AS User_Number,
'30' AS Percentage
AutoGenerate 6;
Thanks
Varun
Hi, you can create a table with enough records to ensure it has all numbers, and from this table load the ones that are different.
rand:
LOAD
ROUND((rand()*19)+1,1) as value
Autogenerate 2000;
UserCodes:
LOAD value as UserCode,
RowNo() as RowNumber
resident rand
Where not exists('UserCode',value);
DROP Table rand;
Then you can use the Lookup() function to assing the values of this table:
Table:
LOAD
Lookup('UserCode', 'RowNumber', RowNo(), 'UserCodes') as User_Number,
'10' AS Percentage
AutoGenerate 2;
Concatenate(Table)
LOAD
Lookup('UserCode', 'RowNumber', RowNo(), 'UserCodes') as User_Number,
'15' AS Percentage
AutoGenerate 3;
...
DROP table UserCodes;
Hi, you can create a table with enough records to ensure it has all numbers, and from this table load the ones that are different.
rand:
LOAD
ROUND((rand()*19)+1,1) as value
Autogenerate 2000;
UserCodes:
LOAD value as UserCode,
RowNo() as RowNumber
resident rand
Where not exists('UserCode',value);
DROP Table rand;
Then you can use the Lookup() function to assing the values of this table:
Table:
LOAD
Lookup('UserCode', 'RowNumber', RowNo(), 'UserCodes') as User_Number,
'10' AS Percentage
AutoGenerate 2;
Concatenate(Table)
LOAD
Lookup('UserCode', 'RowNumber', RowNo(), 'UserCodes') as User_Number,
'15' AS Percentage
AutoGenerate 3;
...
DROP table UserCodes;
Thanks a lot.. it worked.