# Tag Info

### How do I create a weighted collection and then pick a random element from it?

The Soft-coded Probabilities Solution The hardcoded probability solution has the disadvantage that you need to set the probabilities in your code. You can't determine them at runtime. It is also hard ...
• 120k

### How do I create a weighted collection and then pick a random element from it?

Note: I created a C# library for this exact problem The other solutions are fine if you only have a small number of items and your probabilities never change. However, with lots of items or changing ...
Accepted

### 1v1 bartering brain game – see any problems?

Note to readers: just because this answer sorts to the top at the moment does not mean it's the best. This is still a young question, so check out the other answers and vote on them too, or consider ...
• 135k
Accepted

### Random noise based on seed

Java's java.util.Random class usually gives you sequences of pseudorandom numbers which are good enough for use in games1. However, that characteristic only applies ...
• 120k

### How to improve this random number generation in my context?

You could weight the probability of all your letters according to the frequency with which they occur in the language your words are in. A good guideline is the scrabble set. The English version, for ...
• 120k

### How to improve this random number generation in my context?

You don't actually want a random distribution. I point this out explictly, because what we consider "random" for design is usually not true randomness. Now, with that in mind, let's add some ...
• 321

### How do I create a weighted collection and then pick a random element from it?

The Wheel of Fortune solution You can use this method when the probabilities in your item pool have a rather large common denominator and you need to draw from it very often. Create an array of ...
• 120k
Accepted

### Looking for a middle ground between raw random and shuffle bags

My first attempt would be to enlarge the shufflebag, as Mangata suggested in a comment. So instead of 3 guaranteed failures every 4 rolls, you now have 6 guaranteed failures every 8 rolls. If you ...
• 120k

### 1v1 bartering brain game – see any problems?

I can see an exploit for a 1v1 game (i.e. outside of a tournament). As soon as one player is in the lead, their optimal strategy is to completely refuse to make a deal after that. Both players get the ...
• 7,384

### Can you show rng code running in real time in a game?

Yes, you can. There are already online platforms that are doing exactly that, by providing you the hash of the online secret key that is used as the seed for the random generation. Same seed = same ...
• 4,346

### Random noise based on seed

The coordinates should have the same color everyone you restart the program In that case, you'll want to use a deterministic noise function such as Perlin noise or simplex noise. (See this ...
• 3,151
Accepted

### How to create characters randomly with a given skill and weighted abilites

Let's start simple and forget the constraint that skill values should be integers for a moment. If we look at the equation for your job skill: \begin{align} \frac{w_1 s_1 + w_2 s_2 + w_3 s_3 + ...
• 135k

### Random noise based on seed

Let's see what you are doing exactly: You loop through all pixels one by one For each pixel, you use the concatenation of its coordinates as a seed You then start a new random from the given seed and ...
• 191
Accepted

### Unwanted Perlin Noise result

You will need to learn how the terms Octave, Persistence, Frequency, and Lacunarity are used. What you have is a good first step, it looks just like noise should. The basic idea is that you need to ...
• 10.2k

### 1v1 bartering brain game – see any problems?

Neat idea for a game; it's something you can play with a friend while you're waiting in a queue at Disneyland, without needing any equipment or having to remember much game state. The main problem I ...
• 273
Accepted

### Set a 'chance to spawn' for each GameObject in an array

Here's one way to do it, using a custom struct to store object-weight pairs: ...
• 135k
Accepted

### Is Unity 2017 random number generator deterministic across platforms given the same initial seed?

While I haven't had time to do any extensive testing, initial research suggests that the random number generator used is deterministic across different platforms. The exact implementation used is: ...

### How can I get N random objects from array?

You can do this faster than a Hashset with a simple linear scan: ...
• 135k

### Is Unity 2017 random number generator deterministic across platforms given the same initial seed?

Thomas answered the question as asked. The more important question is as follows: Is the Unity 2017 random number generator guaranteed to deliver the same numbers across all current and future ...
• 9,935
Accepted

### Random Direction Vector Relative To Current Direction

Random direction relative to current direction: Assuming you already have an initial direction vector prepared, as per DMGregory's comment on the OP: Generate a ...
• 2,104

### Intuitively, why is 3.5 the average (mean) roll of a six-sided die?

First of all, I wrote a simple program to verify with empirical data that on average we do get a roll of 3.5. (As you tweak the TOTAL_ROLLS closer to 0, the average becomes increasingly unreliable. ...
• 99

### How do I create a weighted collection and then pick a random element from it?

The Hard-coded Probabilities Solution The most simple way find a random item from a weighted collection is to traverse down a chain of if-else statements, where each if-else increases in probably, as ...
• 5,803

### How to devise an algorithm for a person being on a walk?

People walking through a town usually have a destination. So when you want your NPCs wander behavior to look natural, they should also have one. It doesn't need to be a logical destination. Any ...
• 120k

### Are there any formulas/algorithms that could allow level to decide how many dice can be used for a roll?

Yes, there is. numberOfDice = floor( ( Level - 1 ) / 10 ) + 1 The floor method will essentially take the integral part of ...
• 16.3k
Accepted

### How can I create a random deck of 7 cards every time they are all used?

As it happens, I was showing this method to my game mechanics students just this week. :) One of my favourite ways to work with a deck is using an online version of a Fisher-Yates Shuffle (also called ...
• 135k
Accepted

### Is it possible to find a seed based on 10,000 generated random numbers?

Please let me know if this idea is stupid and should be thrown away, thanks! This idea is [ill-founded] and should be thrown away. And we can prove it with a little math! Let's say your seed is a ...
• 135k
Accepted

### Generate random people with demographics

Generate your demographics with weighted random distribution. Before generating the statistics for any individual people, decide the weighted statistics for your groups (i.e. age groups, location, etc....
• 73.3k
Accepted

### Unity Random.Range when using Int, doesnt seem random at all?

The documentation says that you will never get 3, the max is exclusive. public static int Range(int min, int max); Description Returns a random integer number between min [inclusive] and max [...
• 16.3k

### Why are the randomly generated numbers not random?

This is intended: NOTE: This function will return the same value every time the game is run afresh due to the fact that GameMaker: Studio generates the same initial random seed every time to ...
• 93