Nginx (openresty) generating random numbers
53
Based on your error log entry, it appears you have a simple typo.
marth.randomseed(1);
This should read:
math.randomseed(1);
Related videos on Youtube
Author by
gator
Updated on September 18, 2022Comments
-
gator over 1 year
How do I check the equality between four variables? This is for a 3D tic-tac-toe game.
if (b[0][0] == b[1][0] == b[2][0] == p) { line += 1; }
This doesn't work as equivalent is left-to-right. I don't want to do either of the below:
if (b[0][0] == p && b[1][0] == p && b[2][0] == p) { line += 1; } if ((b[0][0] == b[1][0]) && (b[1][0] == b[2][0]) && (b[2][0] == p)) { line += 1; }
All variables are integers, as I know with bools I can just use &&. Is there a better way? I considered:
if ((b[0][0] + b[1][0] + b[2][0]) == (3 * p)) { line += 1; }
Since
p
will be one of three values (0 for neither X or O, 1 for X, 2 for O), it would need only changing the value of O to 4 or something impossible to achieve with three 1s, 0s, or combinations thereof. But it lacks finesse.-
Callat over 7 yearsI am only student so I'm not sure if my recommendation is a good one or not. But did you give any thought to a
switch()
statement? You could have nested cases to compensate for the ifs. -
apple apple over 7 yearswhy you don't want it?
-
gator over 7 years@KazRodgers I could, but there's dozens of lines with similar enough structure (it's for a 3D Tic-Tac-Toe).
-
Pete Becker over 7 yearsBoth of your replacements will work just fine (despite the redundant parentheses in the second one) and either would be a good approach.
-
463035818_is_not_a_number over 7 yearsthen write a function
bool isSame(int,int,int,int)
, but otherwise there is little room for improvement -
Violet Giraffe over 7 yearsNo, there is not a better way.
if (b[0][0] == p && b[1][0] == p && b[2][0] == p)
is the go-to way to write this condition. -
Callat over 7 years@gator I see. What about a function that does the switch case and returns the result. Taking 4 parameters? It's how I would go about it if I had a similar problem.
-
lippea over 6 yearsjust add that "nvx.var.random_num" should actually be ngx
-
-
L.Ech almost 12 yearsWow, and this is what I get for not sleeping
-
Michael Hampton almost 12 yearsSleep takes a lot of time, but it takes less time than debugging. I recommend sleep.
-
Janne Pikkarainen almost 12 years
sleep 28800
is a good idea. -
gator over 7 yearsWell, it's 3D Tic-Tac-Toe, using 8 columns instead of 9 (so 38 conditional checks). I've done the lazy thing and just wrote conditionals for each possible line.