Generate Random Number In Range From Seed

Started by COMMANDO66 on

Topic category: Help with Minecraft modding (Java Edition)

Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Generate Random Number In Range From Seed

Okay, so I'll skip to the details. I need to figure out a way to generate a random number from a seed value, where entering the same seed will always provide the same result. I mean a number I choose, not the world seed.

The application of this has to do with teams and colors. The teams are all stored as numbers here. Each one gets a randomly selected color when it's made. However, there isn't a way to then get that color for a team for applications like coloring boss bars or text. So, I'm thinking of making the random color selection be based off of the team's number, so that way I can just use an algorithm to get the color from the team number in any context I need.

Anything that isn't really random but works close enough for people not to notice in game is fine with me.

Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Nevermind; figured something…
Sun, 07/02/2023 - 02:26

Nevermind; figured something out. Multiplying the input seed by pi and then taking the decimal part gives a convenient output that's close enough to random for me. Nobody will notice the colors repeating and it should be uniform.