Skip to content

Feature Request: Adding 'median' Parameter to RandomInt Mask #300

@youen

Description

@youen

Problem:

Currently, the PIMO tool provides a RandomInt mask for masking data in a JSONline stream. However, it lacks the ability to specify a median parameter for generating random numbers within a range, which can be useful in certain scenarios.

Proposed Solution:

Integrate a 'median' parameter into the RandomInt mask to allow users to control the distribution of random numbers within the specified range.

Example:

version: "1"
masking:
  - selector:
      jsonpath: "age"
    mask:
      randomInt:
        min: 25
        median: 28
        max: 32

Workaround:

While waiting for the integration of the 'median' parameter into the RandomInt mask, users can achieve similar behavior by combining masks. Below is a workaround using existing PIMO masks:

version: "1"
masking:
  - selector:
      jsonpath: "segment"
    masks:
      - add-transient : ""
      - randomChoice:
          - "upper"
          - "lower"

  - selector:
      jsonpath: "value"
    masks:
      - template : |-
            {{ if eq .segment "lower" -}}
              {{- MaskRandomInt (int .min) (int .median) -}}
            {{- else -}}
              {{- MaskRandomInt (int .median) (int .max) -}}
            {{- end }}
      - fromjson: "value"

This workaround calculates a random number within the range defined by 'min' and 'max', centered around the 'median' value. It utilizes the existing MaskRandomInt function and template capabilities to achieve the desired behavior.

try it on pimo play !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions