Random Number Generation

Version 4

    The following two calculations can be used to generate pseudo-random numbers in Tableau.  This works even when using extracts, unlike RAWSQL techniques.

     

    The calculation is a table calc, so random values can be assigned to any level of detail based on the addressing.  The main limitation is that, as a table calc, it can not be used to partition the view.

     

     

    Random Number

    ((PREVIOUS_VALUE(MIN([Seed])) * 1140671485 + 12820163) % (2^24))

    Random Int

    INT([Random Number] / (2^24) * [Random Upper Limit]) + 1

    In the calculations above, [Seed] could be

    • A hard-coded value to give a consistent series of pseudo- random numbers
    • A parameterized value to allow the end-user to change the value or a URL to control the value
    • A randomized seed to give a different set of random numbers each time the data is refreshed.

     

    [Random Upper Limit] is a parameterized upper limit for the calculation.  The Random Int function here gives a random integer from 1 to the upper limit.  Variations of the Random Int calculation could adjust the range or return floats.



    A possibility for randomizing the Seed:


    Seed

    (DATEPART('second', NOW()) + 1) * (DATEPART('minute', NOW()) + 1) * (DATEPART('hour', NOW()) + 1) * (DATEPART('day', NOW()) + 1)



    More details are available here: http://vizpainter.com/random-numbers-even-with-extracts/