This site uses different types of cookies, including analytics and functional cookies (its own and from other sites). To change your cookie settings or find out more, click here. If you continue browsing our website, you accept these cookies.
hi everyone. this is an easy, straightforward question. is there a function (or formula) in alteryx that would produce a series of random numbers biased towards one end of the scale. for instance, if I want to produce random numbers in the range between 0 and 100, and to have some 50% of the random numbers in that range to be between 0-20 and 50 % of the random numbers to be di9stributed between 20-100. preferably, I would like to achieve this without macro, as it seems to be easy and possible, but unfortunately I have not found such solution yet.
The easiest way I can think of to do a "weighted randomization" like this is through math in a formula.
Taking your example, you have a set of 20 numbers (1-20) that you want to be equally probable to a set of 80 numbers (21-100).
To do this just using the RandInt() function in Alteryx, we ideally want to make the two sets have an equal number of points which can be selected. To do this, we need to identify the multiple needed for them to be equally weighted. In this case, we want both sets to be 80 numbers (sort of the "lowest common denominator" that still allows each individual number in the range to be selected).
So, we generate random numbers using RandInt(159)+1 (just to avoid dealing with 0-based numbers), but now we have a lot of numbers that we don't really like or want that are outside our range.
To correct this, we can take all the numbers between 1 and 80 (essentially our new 1-20), and divide by 4 (since that's what we had to multiply by to make the two equal). This leaves us with some decimals, so we can fix this with the CEIL() function which returns the next whole number - so 1.25 rounds up to 2, for example.
Now we still have some numbers between 81 and 160, which need to be brought back in line. Our initial threshold was 100, so we can subtract 60 from numbers larger than 80.
To do this in Alteryx, you would use a formula like this:
If [Randint] <= 80 then CEIL(randint/4) ELSE randint-60 ENDIF
@jeanilieski You can actually use the R tool to create a random skewed distribution.
rbeta(1000,2,5) will create a skewed distribution for you. You can then pump this out into your Alteryx workflow. I attached a workflow that shows what I am talking about. Make sure to run it twice to get the metadata to upload into Alteryx from the R tool.
You can adjust the rbeta function to pass different parameters to get the distribution that you want!
@asilva thank you for you answer. I have additional question. Is it possible to have an input variables before the "R icon" so that in the formula you use in it may consider existing variables? for instance, is it possible instead of "16000" to use a variable name, since the number I want to use would change each time the workflow runs from the schdules : df <- data.frame(dist=rbeta(16000, 2, 5)) write.Alteryx(df, 1)