Random values seem too similar? Harlowe

Twine Version: 2.6.2.0
Harlowe 3.3.5

Hello to all…

In my story, the startup passage is initializing many variables for use in the game. In one section there, it chooses a random temperature for each of the 27 main passages the player would revisit often. The code I’m using there for each passage is

(set: $passageTemperatureIndustry to (random: 1,100))
(set: $passageTemperatureStore to (random: 1,100))
(set: $passageTemperatureRestaurant to (random: 1,100))

etc.
etc.
etc.
For each, of course, I’m only changing the name of the location.

As the player enters these spaces, the temperature of the passage (or environment) will push the player’s body temperature up or down by a few degrees. The body temperature, in turn, has an affect on the player’s happiness which, in turn, has an affect on how this player’s character is able to interact with the world.

And all of this code is working properly. I’ve tested it over and over and over again and it is working. The reason I’m making this post, however, is because the randomness doesn’t seem so random. I notice when I play through this story, the 27 main passages all tend to get assigned temperature values that are similar to one another.

In one playthrough, I notice that most of the passages have been assigned very high values (89, 96, 100, 94, etc., etc.) and, from this, the character’s body temperature gets pushed really high very quickly and then stays there. This causes happiness to go down, eventually to zero, where it stays. In another playthrough, the 27 main passages will all be assigned lower values (27, 14, 32, 18, etc., etc., etc.) and the character’s temperature stays very low for the duration of the game.

I’m looking to create more randomness within those assigned values so they would reflect a wider range (15, 88, 32, 97, 72, 53, 8, etc., etc. etc.). At this time, the only thing I can think that could help is to have the system assign the values for temperature NOT in the startup passage, but as you are entering the passage itself. So Restaurant, for example, wouldn’t have a temperature assigned during startup but would get a value assigned the first time you visit Restaurant.

Can’t help but think, though, that there would be an easier way to pull this off. I’m not manipulating a seed so maybe that’s the ticket? If so, I’m not sure how to code that.

Can any of you make suggestions that would provide more random values to that code or should I just assign the values as the player enters the spaces for the first time?

Thanks!

1 Like

That’s random numbers for you… they’re usually more random than you want. Try picking 27 values you want to see and shuffling them into a random order.

1 Like

Random is random.

If what you really want is a distribution around a central point, you either need a sufficiently large sampling, or some sort of weighted averages. Try generating half the numbers with a range covering the lower two thirds of values you desire and the other half a range in the upper two thirds. Then distribute those randomly to the locations. It is still possible to get uneven distributions this way, but it is a lot less likely. Tweak the ranges until you get something you like.

1 Like

So…update now that some time has passed. I actually found a way to make this work a lot better.

Before, the system was choosing the a random temperature between 1 and 100 for all of these 27 passages one after the other during startup. The problem, as was previously noted, is that the system seemed to pick random numbers from a very narrow band/range so the temperatures for the locations/passages were mostly all high, all low, or all in the mid range.

I made some changes and have tested several times. I can confirm I’ve found something that works better for my situation. The problem, it seems, is allowing the system to pick all of these random values one after the other. To fix, I decided to try allowing the system to pick the values at different times.

I’m still allowing the system to pick random values for each passage during startup as a means to initialize the variables but, I’m updating those values with a newly generated random number when you approach the passage for the first time. For example, the electronics store and pharmacy are both connected to the major landmark area. You can only access the electronics store and pharmacy from major landmark. In turn, you can only access major landmark from the hotel area. So, when you enter the hotel passage for the first time, I’m allowing the system to generate a new random value for temperature for major landmark. This only happens during your first visit to the hotel so the temperature for major landmark will remain the same for the duration of the game. When you enter major landmark for the first time, that passage will generate new random values for temperatures to be used at the electronics store and the pharmacy.

The old system generated values that looked like - 89, 96, 78, 80, 98, etc. etc. or 23, 14, 32, 1, 18, etc., etc.

I visited the passages for testing purposes and now got these values - 6, 64, 91, 83, 54, 97, 50, 13, 20, 33, 14, 59, 100, 90, 3, 91, 33, 12, 97, 90, and 91. Each time I play, I consistently get values in a much broader range that seems to encompass the full range of the random pull so this is working nicely. I understand, of course, that there is a chance that sometimes the values will all seem very high or very low and I’m ok with that. My issue was that, before, it was guaranteed to stay in one area or another so the point of being random was pretty moot.

Two responses here provided other great ways to resolve this issue. And while those would certainly work, and while I seriously took both into consideration, I found myself having mental block when trying to decide which passages would have higher or lower temps. This method I’m now using seems to be the fix most suited for my project.

I hope this information helps others.

Thanks again for providing feedback and recommending such great solutions!

Thanks,

Kevin

2 Likes