Genesys Cloud - Main

 View Only

Sign Up

  Thread closed by the administrator, not accepting new replies.
  • 1.  Random numbers in a bot flow

    Posted 06-27-2023 18:08
    No replies, thread closed.

    Since of this writing (2023/06/27) the Random() and RandomInt() functions to do not work in bot flows (ugggh), below is the easiest way I've found to generate a random number (more than 0-59) from within a bot flow:

    ToInt( Substring( ToString( GetCurrentDateTimeUtc() ), 20, 3) )

    The above will generate a "pseudo-random" number from 0-999, based on the number of milliseconds in the current UTC time.

    Yes this looks a bit odd...   One would think one could just get the milliseconds component off of the UTC time, alas - there is no Millisecond() function (only a Second() function).  

    So the above gets the current UTC time (which does have milliseconds inherent), converts this to a String, such as:

    2009-01-10T06:30:00.000Z

    pulls off the millisecond component (ie: that between the "." and "Z" in the above example)  and then returns that as an integer.


    Of course if you need a different range of numbers, you can always divide the result by 1000 and multiple by the total range of numbers.  

    ie: if you need a random number from 0-49 (upper range is 50), you'd use:

    ( ToInt( Substring( ToString( GetCurrentDateTimeUtc() ), 20, 3) ) / 1000 ) * 50

    Of course the resolution for this is only 1000, to get better you may wish to call the above multiple times and multiply the results together, or other contortions (an exercise left to the reader).

    Not "true" random, but close enough.

    Hopefully we'll get better function coverage in bot flows in a new release of Architect in the very near future (LOTS of gaps between bot flows and standard flows at the moment).  

    Hope this helps someone!


    Brian


    #ConversationalAI(Bots,AgentAssist,etc.)
    #DigitalChannels
    #Implementation
    #Routing(ACD/IVR)
    #Unsure/Other

    ------------------------------
    Brian Raynor
    Principal Architect
    Verizon Business Group
    ------------------------------


  • 2.  RE: Random numbers in a bot flow

    Posted 06-27-2023 21:47
    No replies, thread closed.

    Slightly simpler (in my opinion)  

    ToInt(DateTimeDiff(GetCurrentDateTimeUtc(), MakeDateTime(1970, 1, 1))) % 1000

    The 2nd date doesn't matter, just pick one and use it.  Then mod by whatever the range of numbers you want.  This will get 0-999



    ------------------------------
    Melissa Bailey
    Genesys - Employees
    ------------------------------



  • 3.  RE: Random numbers in a bot flow

    Posted 06-28-2023 10:58
    No replies, thread closed.

    Thanks Melissa, yes, that is a bit more straightforward (and probably executes a tad bit faster on the backend).  



    ------------------------------
    Brian Raynor
    Principal Architect
    Verizon Business Group
    ------------------------------