Clarity

  • 1.  Random function in GEL script

    Posted Aug 18, 2015 08:07 AM

    Hi all,

     

    I'd like to ask if exists some "random" function which can be used in GEL script. Has anyone ever heard about it?

    I couldn't find anything function like that with GEL.

     

    Example:

     

    Instead of:

    ...

    <util:sleep millis="6000"/>

    ...


    I'd like to have something like:

    ...

    <util:sleep millis=random(1000-6000)/>

    ...

     

    Thanks a lot.

     

    Matej



  • 2.  Re: Random function in GEL script
    Best Answer

    Posted Aug 18, 2015 03:48 PM

    Does this demonstration help:

     

    <gel:script
      xmlns:core="jelly:core"
      xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
    >

     

    <core:new className="java.util.Random" var="rnd" />

     

    <core:forEach indexVar="i" begin="1" end="10">
      <core:invoke var="result" on="${rnd}" method="nextInt">
        <core:arg type="int" value="5000" />
      </core:invoke>
      <gel:out>${i}: ${result+1000}</gel:out>
    </core:forEach>

     

    </gel:script>

     

    1: 5980

    2: 2486

    3: 2451

    4: 1152

    5: 3979

    6: 1441

    7: 3237

    8: 5224

    9: 3431

    10: 4433

     

    Hopefully you only need to use util:sleep for some test case scenarios.  Its usage can rapidly cause serialization (i.e. a slowdown of script execution throughput) in your system.



  • 3.  Re: Random function in GEL script

    Posted Aug 19, 2015 02:53 AM

    Thanks Nick,

     

    This is exactly what I was looking for. Working fine and yes I only need it to sleep one process randomly (precisely hard-coded time caused executing many processes at the same time again).

     

    Matej