How would I assign a random number using rand or another function if I want the range to be between 0 to 16?
Solved! Go to Solution.
Hi @ts22
Try the formula:
rand() * 16
The expression rand() generates a number between 0 - 1 so just multiply by 16, and set the data type as Int32 or something, so that there are no decimals.
If you want Double to be your Data type, then use something like ceil(rand() * 16) instead.
Hope that helps.
- Andrew
Thank you, I appreciate it!
Is there a way to use RandInt and not have it assign duplicate values? I noticed it will give me two 8's instead of just a singular 0-16 for each number.
Hi @ts22
I don't have a fancy solution for you but I can suggest a method I have outlined in my head.
1. Use a Record ID tool to "Sort" your records as they are now.
2. Use a Formula tool and use the formula rand(). There are quite a few significant figures so hopefully there are no duplicate values (odds are low). You can use a unique tool as a checker for this.
3. Use a Sort tool and rank the field which has the random numbers.
4. Use a Multi-Row formula to rank the records in this new order.
5. Use another Sort tool to sort by Record ID to return your records to the order they were in previously.
I have attached my workflow below for you.
- Andrew
Hi @ts22
What do you want use the random numbers for? Why is it important not to have duplicates?
Is it to apply a random sort order to your data? if so then create a new field with Rand() as the formula and sort by this new field.
Is it to select a random subset of the data? In that case use the Sample tool.
Dan
probably not since that goes against the definition of "random".
I think this post is very smart. I'll be applying something of this sort to a Scrabble optimizer, for which I am determined to make a unique solution.