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);
Share:
53

Related videos on Youtube

gator
Author by

gator

Updated on September 18, 2022

Comments

  • gator
    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
      Callat over 7 years
      I 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
      apple apple over 7 years
      why you don't want it?
    • gator
      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
      Pete Becker over 7 years
      Both 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
      463035818_is_not_a_number over 7 years
      then write a function bool isSame(int,int,int,int), but otherwise there is little room for improvement
    • Violet Giraffe
      Violet Giraffe over 7 years
      No, 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
      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
      lippea over 6 years
      just add that "nvx.var.random_num" should actually be ngx
  • L.Ech
    L.Ech almost 12 years
    Wow, and this is what I get for not sleeping
  • Michael Hampton
    Michael Hampton almost 12 years
    Sleep takes a lot of time, but it takes less time than debugging. I recommend sleep.
  • Janne Pikkarainen
    Janne Pikkarainen almost 12 years
    sleep 28800 is a good idea.
  • gator
    gator over 7 years
    Well, 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.