Commit bb25539f authored by platypro's avatar platypro

Updated templates to more closely match new features. Also made unirand better.

parent 1a25a3a3
{
"name" : "Arithmetic",
"calculator" : "banned",
"randMax" : 400,
"preamble" : "Evaluate.",
"variables" : {
"val_1": "-option:max_1:min_1",
......
{
"name" : "Test set",
"questions": [
{
"id":"basic",
"numQuestions":5
},
{
"id":"net.platypro.ptable",
"numQuestions":5
......
{
"name" : "{{name}}",
"type" : "normal",
"calculator" : "{{calculator}}",
"randMax" : 200,
"variables" : {
"value": "$option:maxValue",
},
"preamble" : "Evaluate.",
"options": { },
"options": {
"maxValue" : 5,
},
"static": [ ]
}
......
-- QuizGrind script for exercise {{name}}
createWidget("textView", nil, {text = "Sample Text"})
createWidget("textInput", "sample", {hint = "Sample Input"})
createWidget("numberInput", variables["value"],
{hint = string.format("Sample Value (%d)", variables["value"])})
{
"name" : "{{name}}",
"type" : "static",
"calculator" : "{{calculator}}",
"hints": ["Sample Hint"],
"templates":[ ],
"widgets": [ ]
"widgets": [
{
"type":"textView",
"options":{"text": "This is a label."}
}
]
}
......@@ -3,27 +3,23 @@
#include "pcg_basic.h"
int gcd(int a, int b) {
int temp;
if(a < 0) a = -a;
if(b < 0) b = -b;
if(a == b) return b;
if(b > a)
{
temp = b;
b = a;
a = temp;
}
while((temp = a % b) != 0) {
a = b;
b = temp;
}
return b;
}
uint32_t primes[] = {
2 ,3 ,5 ,7 ,11 ,13 ,17 ,19 ,23, 29,
31 ,37 ,41 ,43 ,47 ,53 ,59 ,61 ,67, 71,
73 ,79 ,83 ,89 ,97 ,101,103,107,109,113,
127,131,137,139,149,151,157,163,167,173,
179,181,191,193,197,199,211,223,227,229,
233,239,241,251,257,263,269,271,277,281,
283,293,307,311,313,317,331,337,347,349,
353,359,367,373,379,383,389,397,401,409,
419,421,431,433,439,443,449,457,461,463,
467,479,487,491,499,503,509,521,523,541,
601,659,733,809,863,941,1013,1069,1151,
1283,1289,1367,1447,1499,1579,1637,1723,
429494501, 429493501, 429486647, 100001053, 100002421, 10001567
};
uint32_t numprimes = NUMELEMENTS(primes);
void unirand_seed(struct unirand_t* rand, uint32_t top)
{
......@@ -33,14 +29,18 @@ void unirand_seed(struct unirand_t* rand, uint32_t top)
rand->prime = 1;
return;
}
int prime = rand->offset = pcg32_random() % (top-1) + 1;
rand->offset = pcg32_random() % (top-1) + 1;
uint32_t* prime = primes + numprimes - 1;
do {
if(gcd(top, prime) == 1) break;
prime = (prime < top ? prime + 1 : 1);
} while(prime != rand->offset);
rand->prime = prime;
while(*prime >= top && ((top % *prime) == 0))
{
prime --;
if(prime == primes) prime = primes + numprimes - 1;
}
} while(pcg32_random() % 3);
rand->prime = *prime;
}
uint32_t unirand(struct unirand_t* rand, uint32_t* at)
......
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