Skip to content

Commit db86856

Browse files
committed
feat: add output type option for random integer generation operation
1 parent 9f7d1bf commit db86856

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/core/operations/PseudoRandomIntegerGenerator.mjs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ class PseudoRandomIntegerGenerator extends Operation {
5757
"name": "Delimiter",
5858
"type": "option",
5959
"value": DELIM_OPTIONS
60+
},
61+
{
62+
"name": "Output",
63+
"type": "option",
64+
"value": ["Raw", "Hex", "Decimal"]
6065
}
6166
];
6267

@@ -71,7 +76,7 @@ class PseudoRandomIntegerGenerator extends Operation {
7176
* @returns {string}
7277
*/
7378
run(input, args) {
74-
const [numInts, minInt, maxInt, delimiter] = args;
79+
const [numInts, minInt, maxInt, delimiter, outputType] = args;
7580

7681
if (minInt === null || maxInt === null) return "";
7782

@@ -96,9 +101,23 @@ class PseudoRandomIntegerGenerator extends Operation {
96101
for (let i = 0; i < numInts; i++) {
97102
const result = this._generateRandomValue(rejectionThreshold);
98103
const intValue = min + (result % range);
99-
output.push(intValue.toString());
104+
105+
switch (outputType) {
106+
case "Hex":
107+
output.push(intValue.toString(16));
108+
break;
109+
case "Decimal":
110+
output.push(intValue.toString(10));
111+
break;
112+
case "Raw":
113+
default:
114+
output.push(Utils.chr(intValue));
115+
}
100116
}
101117

118+
if (outputType === "Raw") {
119+
return output.join("");
120+
}
102121
return output.join(delim);
103122
}
104123

0 commit comments

Comments
 (0)