CFD random Number

Discussion in 'Call Flow Designer' started by Tomas Raska, Dec 15, 2017.

Thread Status:
Not open for further replies.
  1. Tomas Raska

    Joined:
    Aug 18, 2017
    Messages:
    58
    Likes Received:
    6
    Hello,
    how can I store to variable "Module Assign a Variable" random Number from range 1 to 5?

    Thanks
     
  2. edossantos

    edossantos Support Team
    Staff Member 3CX Support

    Joined:
    Jun 27, 2007
    Messages:
    1,080
    Likes Received:
    77
    Hello @Tomas Raska,

    When you assign a value to a variable using the "Assign a variable" component, you can use any C# expression to calculate the value. Then, you can use for example the Random class available in C# as follows:
    new Systen.Random().Next(1,6)

    That will return a number between 1 and 5.

    Regards.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Tomas Raska

    Joined:
    Aug 18, 2017
    Messages:
    58
    Likes Received:
    6
    Thanks, but this Expression not working
    upload_2017-12-17_13-34-16.png
    Compiling the created source code to .NET library...
    Error compiling source code to .NET library: (1,12): error CS0116: A namespace cannot directly contain members such as fields or methods
    Error compiling source code to .NET library: (3,5): error CS0246: The type or namespace name 'Random' could not be found (are you missing a using directive or an assembly reference?)
    Error compiling source code to .NET library: (3,25): error CS0246: The type or namespace name 'Random' could not be found (are you missing a using directive or an assembly reference?)
     
  4. edossantos

    edossantos Support Team
    Staff Member 3CX Support

    Joined:
    Jun 27, 2007
    Messages:
    1,080
    Likes Received:
    77
    Hello @Tomas Raska,

    Just tested the expression, and it works without any problem. Please note that there was a typo, it's "Random" and not "Randon". Using the following expression I'm able to successfully build the project:
    new System.Random().Next(1,6)

    If you're still having issues please check if your project is not having an error somewhere else.

    Kind regards.
    Ernesto.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. Tomas Raska

    Joined:
    Aug 18, 2017
    Messages:
    58
    Likes Received:
    6
    Thanks, when I created new Project with only one field "Assign Variable" is working.
    Old Project too with only one field "Assign variable" reported error.
     
  6. edossantos

    edossantos Support Team
    Staff Member 3CX Support

    Joined:
    Jun 27, 2007
    Messages:
    1,080
    Likes Received:
    77
    There must be some difference in the other project for sure... But the expression works. Thanks for confirming that.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Thread Status:
Not open for further replies.