Forum Discussion
How to generate random number based on seed value?
- 8 years ago
Hi ppgandhi11,
Based on my test, you can refer to below steps:
1.I have entered some sample data to test for your problem like the picture below:
2.
2.Create a new table
RandTable = SUMMARIZE('Table1',Table1[ID],"A",RAND())
3.Create relationship between the two tables.
4.
4.Create a calculated column in ‘Table1’ and now you can see the correct result.
Rand = RELATED(RandTable[A])
You can also download the PBIX file to have a view.
Regards,
Daniel He
upon looking deeper, actually it does not seem to be working. The random numbers are always generated with only 2 decimal places (i think that is the problem). The range it picks is: 0.00 to 1.00 I am using rand() function.
It generates same random number for same ID which is correct, but it is generating same random number for different IDs too which is incorrect.
Below is the sample result returned.
ID RandomNumber
1 0.01
2 0.05
3 0.05
4 0.95
1 0.01
As you can see above, for ID 1, it generates 0.01 consistently so that is fine.
However, for both ID 2 and 3, it generates 0.05 which is incorrect. It should have generated 2 different random numbers for them.
How to achieve this? Ideally the random number generated should be large decimal (e.g. 7-8 decimal places) to avoid this kind of situations. Thanks!
Your help is much appreciated.
Oh, I changed the field to decimal with 10 digits in the modeling tab and it worked out well. It is fixed! Thanks!