Implement RANDOMIZE
This commit is contained in:
@@ -758,15 +758,29 @@ class BuiltinFunction
|
||||
{
|
||||
PetitComputer.RGBRead(color, R, G, B, A);
|
||||
}
|
||||
static int RND(int max)
|
||||
static void RANDOMIZE(PetitComputer p, int seedid)
|
||||
{
|
||||
import std.random;
|
||||
return uniform(0, max);
|
||||
p.random.randomize(seedid);
|
||||
}
|
||||
static double RNDF()
|
||||
static void RANDOMIZE(PetitComputer p, int seedid, int seed)
|
||||
{
|
||||
import std.random;
|
||||
return uniform(0.0, 1.0);
|
||||
p.random.randomize(seedid, seed);
|
||||
}
|
||||
static int RND(PetitComputer p, int seedid, int max)
|
||||
{
|
||||
return p.random.random(seedid, 0, max);
|
||||
}
|
||||
static double RNDF(PetitComputer p, int seedid)
|
||||
{
|
||||
return p.random.random(seedid, 0.0, 1.0);
|
||||
}
|
||||
static int RND(PetitComputer p, int max)
|
||||
{
|
||||
return p.random.random(0, 0, max);
|
||||
}
|
||||
static double RNDF(PetitComputer p)
|
||||
{
|
||||
return p.random.random(0, 0.0, 1.0);
|
||||
}
|
||||
@StartOptional("W")
|
||||
static void DTREAD(out int Y, out int M, out int D, out int W)
|
||||
|
||||
@@ -21,6 +21,7 @@ import otya.smilebasic.console;
|
||||
import otya.smilebasic.graphic;
|
||||
import otya.smilebasic.dialog;
|
||||
import otya.smilebasic.program;
|
||||
import otya.smilebasic.random;
|
||||
const static rot_test_deg = 45f;
|
||||
const static rot_test_x = 0f;
|
||||
const static rot_test_y = 1f;
|
||||
@@ -275,6 +276,7 @@ class PetitComputer
|
||||
Projects project;
|
||||
void init()
|
||||
{
|
||||
random = new Random();
|
||||
project = new Projects(".");
|
||||
// DerelictGL.load();
|
||||
if(!exists(resourcePath))
|
||||
@@ -1752,4 +1754,5 @@ class PetitComputer
|
||||
{
|
||||
return a << 24 | r << 16 | g << 8 | b;
|
||||
}
|
||||
public Random random;
|
||||
}
|
||||
|
||||
26
SMILEBASIC/random.d
Normal file
26
SMILEBASIC/random.d
Normal file
@@ -0,0 +1,26 @@
|
||||
module otya.smilebasic.random;
|
||||
import std.random;
|
||||
|
||||
class Random
|
||||
{
|
||||
LinearCongruentialEngine!(uint, 16_807, 0, 2_147_483_647)[8] engine;
|
||||
public this()
|
||||
{
|
||||
foreach (e; engine)
|
||||
{
|
||||
e.seed(unpredictableSeed);
|
||||
}
|
||||
}
|
||||
public T random(T)(int seedid, T min, T max)
|
||||
{
|
||||
return uniform(min, max, engine[seedid]);
|
||||
}
|
||||
public void randomize(int seedid)
|
||||
{
|
||||
engine[seedid].seed(unpredictableSeed);
|
||||
}
|
||||
public void randomize(int seedid, int seed)
|
||||
{
|
||||
engine[seedid].seed(seed);
|
||||
}
|
||||
}
|
||||
2
dub.json
2
dub.json
@@ -4,7 +4,7 @@
|
||||
"derelict-sdl2": "~>1.9.7",
|
||||
"derelict-gl3": "*"
|
||||
},
|
||||
"sourceFiles": ["SMILEBASIC/bg.d","SMILEBASIC/builtinfunctions.d","SMILEBASIC/compiler.d","SMILEBASIC/error.d","SMILEBASIC/main.d","SMILEBASIC/node.d","SMILEBASIC/parser.d","SMILEBASIC/petitcomputer.d","SMILEBASIC/sprite.d","SMILEBASIC/systemvariable.d","SMILEBASIC/token.d","SMILEBASIC/type.d","SMILEBASIC/VM.d","SMILEBASIC/project.d","SMILEBASIC/console.d","SMILEBASIC/graphic.d","SMILEBASIC/dialog.d","SMILEBASIC/data.d","SMILEBASIC/program.d"],
|
||||
"sourcePaths": ["SMILEBASIC/"],
|
||||
"targetType": "executable",
|
||||
"buildRequirements": ["allowWarnings"],
|
||||
"targetPath": "out",
|
||||
|
||||
Reference in New Issue
Block a user