Azure Logic应用中的随机列表

时间:2018-12-18 00:25:44

标签: azure azure-logic-apps

是否可以仅使用Logic应用程序中WDL的函数来随机化数组的元素?

2 个答案:

答案 0 :(得分:0)

在LogicApp中没有直接的随机方法。

我想您可以提出一些可以完全在Logic App中对列表进行伪随机化的模式,但是....

处理此问题的更“正确”方法是使用Function。

答案 1 :(得分:0)

假设您有1到10个数组

enter image description here

您创建空的随机数组变量

enter image description here

和一个临时值(在以后的步骤中使用,因为不允许自引用)

enter image description here

然后您像这样创建直到循环

enter image description here

直到条件为“等于10”且表达式为

length(variables('Randomized'))

如果条件为“等于1”和表达式

rand(0,2)

如果为真,路径已将 temp 变量设置为

union(variables('Randomized'), createArray(variables('Array')[iterationIndexes('Until')]))

并且如果为假,路径已将 temp 变量设置为

union(createArray(variables('Array')[iterationIndexes('Until')]), variables('Randomized'))

在条件语句中,将随机变量设置为 temp

在最后一次迭代之后,您将获得随机的输入表

enter image description here

完整代码示例

{
  "definition": {
    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
    "actions": {
      "Initialize_Start_Date": {
        "inputs": {
          "variables": [
            {
              "name": "Array",
              "type": "Array",
              "value": [
                1,
                2,
                3,
                4,
                5,
                6,
                7,
                8,
                9,
                10
              ]
            }
          ]
        },
        "runAfter": {},
        "type": "InitializeVariable"
      },
      "Initialize_variable": {
        "inputs": {
          "variables": [
            {
              "name": "Randomized",
              "type": "Array",
              "value": []
            }
          ]
        },
        "runAfter": {
          "Initialize_Start_Date": [
            "Succeeded"
          ]
        },
        "type": "InitializeVariable"
      },
      "Initialize_variable_2": {
        "inputs": {
          "variables": [
            {
              "name": "temp",
              "type": "Array"
            }
          ]
        },
        "runAfter": {
          "Initialize_variable": [
            "Succeeded"
          ]
        },
        "type": "InitializeVariable"
      },
      "Until": {
        "actions": {
          "Condition": {
            "actions": {
              "Set_Temp_(join_on_left)": {
                "inputs": {
                  "name": "temp",
                  "value": "@union(variables('Randomized'), createArray(variables('Array')[iterationIndexes('Until')]))"
                },
                "runAfter": {},
                "type": "SetVariable"
              }
            },
            "else": {
              "actions": {
                "Set_Temp_(join_on_right)": {
                  "inputs": {
                    "name": "temp",
                    "value": "@union(createArray(variables('Array')[iterationIndexes('Until')]), variables('Randomized'))"
                  },
                  "runAfter": {},
                  "type": "SetVariable"
                }
              }
            },
            "expression": {
              "and": [
                {
                  "equals": [
                    "@rand(0,2)",
                    1
                  ]
                }
              ]
            },
            "runAfter": {},
            "type": "If"
          },
          "Set_randomized_from_temp": {
            "inputs": {
              "name": "Randomized",
              "value": "@variables('temp')"
            },
            "runAfter": {
              "Condition": [
                "Succeeded"
              ]
            },
            "type": "SetVariable"
          }
        },
        "expression": "@equals(length(variables('Randomized')), 10)",
        "limit": {
          "count": 60,
          "timeout": "PT1H"
        },
        "runAfter": {
          "Initialize_variable_2": [
            "Succeeded"
          ]
        },
        "type": "Until"
      }
    },
    "contentVersion": "1.0.0.0",
    "outputs": {},
    "parameters": {},
    "triggers": {
      "manual": {
        "inputs": {
          "schema": {}
        },
        "kind": "Http",
        "type": "Request"
      }
    }
  }
}