Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
youen opened this issue May 6, 2024 · 0 comments
Open

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

youen opened this issue May 6, 2024 · 0 comments

Comments

@youen
Copy link
Member

youen commented May 6, 2024

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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant