There is a while
in which the nth number of conditions. Tell me, please, how to ensure that at every step the conditions are arranged in a random order?
- oneWrite each condition to an array and substitute a value with a random key? - smellyshovel
- Add an example of conditions. What conditions can be in a cycle? - Stepan Kasyanenko
|
1 answer
args is an array of arguments.
You can also use a function that takes random data and will perform certain actions based on this data.
The number of conditions in one iteration already choose.
var args=[1,2,3,4,5,6,7,8,9]; var q=5; var w=0; while((w++)<10){ if(q<args[~~(Math.random()*args.length)]){ console.log('true'); }else{ console.log('false'); } }
An example with an array of functions in which the conditions are stated:
var args=[ function(e){ if(e<3){ console.log('a1 true'); }else{ console.log('a1 false'); } }, function(e){ if(e==3){ console.log('a2 true'); }else{ console.log('a2 false'); } }, function(e){ if(e>3){ console.log('a3 true'); }else{ console.log('a3 false'); } } ]; var argsLength=args.length; var w=0; while((w++)<10){ q=[]; while(q.length<argsLength){ randomIndex=~~(Math.random()*argsLength); if(q.indexOf(randomIndex)<0){ q.push(randomIndex); } } console.log(q); console.log('new random args '+w); r=0; while(r<argsLength){ args[q[r]](~~(Math.random()*6)); r++; } }
- thanks for the answer, the idea was very pondered) - Oleh Motyka
|