Generate Random Numbers
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Labels:
- Datasets
- Developer Tools
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thank you, I appreciate it!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
RandInt(n): Returns a random integer between 0 and the specified parameter
RandInt(10) returns 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 or 10
RandInt(5000) returns a random whole number between 0 and 5000, such as 741
Cheers,
Mark
Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
probably not since that goes against the definition of "random".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
