community
cancel
Showing results for 
Search instead for 
Did you mean: 

Alteryx designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.
SOLVED

Random Number Generator for different items

Asteroid

Hi,

 

I'm trying to create a random number field and I noted that the RandInt(n) would be perfect, however, I would like to only like different numbers generated for different items and types. Is it possible to do this without summarizing the rows because I require them to be separated. Example below:

 

Input:

Item #Item NameTypeCompliments
1ApplesGoodMangoes
2NappiesGoodBeer
3CokeBadChips
1ApplesBadBread
1ApplesGoodMangoes

 

Desired Output:

Item #Item NameTypeComplimentsRandom Number
1ApplesGoodMangoes506
2NappiesGoodBeer679
3CokeBadChips12
1ApplesBadBread1075
1ApplesGoodChips506

 

Thanks

Alteryx Partner

I believe you could do it where you sort the data on item name and type. Allocate a random number to each record and then use the multi-row formula to look back to the previous record and allocate the random number from above if the two fields are the same otherwise keep the existing one. 

 

I however think it would be easier to take a separate stream, summarize to the two fields you want, allocate the random number and then join this back to your original dataset on those two fields.

 

Both methods should work, let me know if you need an example of either.

I have a small macro which I have used to generate unique sequences before.

 

I placed in the gallery at https://gallery.alteryx.com/#!app/Permutation/565eed05aa690a1254277b2c

 

You can use it to generate a large enough set of random numbers and then join to the input set.

 

Had misread the problem. Ned's solution is a good one.

Founder
Founder

What you are looking for is basically a checksum instead of a random #.  An MD5 is a random # that is tied to specific input values.  Normally it returns the number as a hex string, but that is easy to convert to a number in Alteryx:

 

HexToNumber(Left(MD5_UNICODE([Field1]+[Field2]),7))

This will give you a random # between 0 and ‭268435455‬.  If you want the random number to be within a specific range (say 0 - 1000), that is easy with math:

HexToNumber(Left(MD5_UNICODE([Field1]+[Field2]),7))*1000/268435455
Asteroid

Thank you so much - it worked great! :smileyvery-happy:

Labels