Commit 38c3d9df by Иван Кубота

random tune

parent 413104d9
Pipeline #546 failed with stage
...@@ -99,7 +99,7 @@ module.exports = { ...@@ -99,7 +99,7 @@ module.exports = {
let used = {}, generated = 0; let used = {}, generated = 0;
let last = {c:-1}, let last = {c:-1},
list = [], list = [],
globalMaxTries = args.count*5, globalMaxTries = args.count*500,
globalTries = 0; globalTries = 0;
if(args.count>100)args.count = 100; if(args.count>100)args.count = 100;
while(generated<args.count && globalTries < globalMaxTries){ while(generated<args.count && globalTries < globalMaxTries){
...@@ -109,18 +109,19 @@ module.exports = { ...@@ -109,18 +109,19 @@ module.exports = {
p: seeded() > 0.7, p: seeded() > 0.7,
c: 1 c: 1
}; };
if( last.c === 1 && seeded() > 0.5 ){ if( seeded() > 0.3 ){
//if( last.c === 1 && seeded() > 0.5 ){
cur = { cur = {
c: 2 c: 2
}; };
let id, tries = 0; let id, tries = 0;
do{ /*do{
id = rand(1, countStdQ); id = rand(1, countStdQ);
tries++; tries++;
if(tries === 100){ if(tries === 100){
break; break;
} }
}while('2.'+id in used); }while('2.'+id in used);*/
if(tries===100) if(tries===100)
continue; continue;
cur.id = id; cur.id = id;
...@@ -132,8 +133,16 @@ module.exports = { ...@@ -132,8 +133,16 @@ module.exports = {
if(cur.c === 1){ if(cur.c === 1){
result = ctx.quizGenerator( cur.m ? 'checkbox' : 'radio', cur.p ); result = ctx.quizGenerator( cur.m ? 'checkbox' : 'radio', cur.p );
}else{ }else{
let counter = 0, r = 2;
result = ctx.standardGenerator(()=>cur.id) do{
r = rand( 1, countStdQ );
let q = data.standardQuestions[ r ];
if(q && !(q.category_id+'.'+q.qID in used))
break;
counter++;
}while(counter < 100);
result = ctx.standardGenerator(()=>r);
if(result)
if(!result){ if(!result){
tries = 100; tries = 100;
break; break;
...@@ -143,8 +152,9 @@ module.exports = { ...@@ -143,8 +152,9 @@ module.exports = {
if(tries === 100) if(tries === 100)
break; break;
}while(result.categoryId+'.'+result.productId in used); }while(result.categoryId === last.c || result.categoryId+'.'+result.productId in used);
if(tries !== 100){ if(tries !== 100){
cur.c = result.categoryId;
used[result.categoryId+'.'+result.productId] = true; used[result.categoryId+'.'+result.productId] = true;
list.push(result); list.push(result);
......
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 to comment