Commit 030d176e by amir

randomize strings

parent 68b82007
Showing with 8 additions and 1 deletions
...@@ -52,6 +52,10 @@ function randomIntBetween(minValue,maxValue){ ...@@ -52,6 +52,10 @@ function randomIntBetween(minValue,maxValue){
return parseInt(Math.min(minValue + (Math.random() * (maxValue - minValue)),maxValue)); return parseInt(Math.min(minValue + (Math.random() * (maxValue - minValue)),maxValue));
} }
function randomStringBetween(values){
return values[parseInt(Math.random() * values.length)]
}
function handleChild(child, parent) { function handleChild(child, parent) {
var obj = parent[child]; var obj = parent[child];
switch (typeof obj){ switch (typeof obj){
...@@ -60,7 +64,7 @@ function handleChild(child, parent) { ...@@ -60,7 +64,7 @@ function handleChild(child, parent) {
break; break;
case 'string': case 'string':
var args = obj.split(":"); var args = obj.split(":");
if (args.length == 4){ if (args.length >= 4){
if (args[0] == 'R'){ if (args[0] == 'R'){
var startRange = args[2]; var startRange = args[2];
var endRange = args[3]; var endRange = args[3];
...@@ -72,6 +76,9 @@ function handleChild(child, parent) { ...@@ -72,6 +76,9 @@ function handleChild(child, parent) {
case 'F': case 'F':
parent[child] = randomFloatBetween(startRange,endRange); parent[child] = randomFloatBetween(startRange,endRange);
break; break;
case 'S':
parent[child] = randomStringBetween(args.slice(2,args.length));
break;
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment