[plugin] Not Quite Random

Post your completed addons to share with the community

Post » Wed Oct 12, 2016 4:31 pm

Hi. A few psuedo-random number generator plugins are already available, but none of them achieve what this plugin can do (AFAIK...). My current project needed this, so I rolled my sleeves up, learned a bit of JavaScript and created my first ever c2 plugin!! Please feel free to use it in your projects; if you make it big as a result then shout out to me and I'll be satisfied.

What does it do? This plugin creates random numbers that conform to non-linear distribution curves. The random(range) expression offers no bias to producing numbers that are near the middle of the range. For example, with a range of 100, 1 is as likely to be returned as is 50. That might fit your needs, but if you want to scatter or spread your random numbers with some bias then this plugin should provide a useful method.

For example - here's a scatter of returned values from a Math.random() expression (x axis = 0 to 1, y axis = frequency, from 50k runs):

Image


And here are a few examples of what can be produced by this plugin:

Image



Demo

Plugin

The plugin is on Github, so feel free to modify / improve etc as you desire. The .js library was obtained from here and a good demo of its speed and versatility can be found here - although not all methods have been implemented because I didn't see the need for some of the distribution patterns.

Distribution options available (% figures are speed of execution compared to Math.random):


    1 Precision Normal Distribution - Gaussian distribution (20%)
    2 Precision Custom Loaded - High Quality (20%)
    3 Range Float - Uniformly distributed numbers in range (like random()) (90%)
    4 Range Integer - Uniformly distributed integers (inclusive) (70%)
    5 Range Loaded - Middle/End loaded numbers in range (30%)
    6 Game Normal - Normal shaped game distribution (30%)
    7 Game Spire - Spire shaped game distribution (50%)
    8 Game Thorn - Thorn shaped game distribution (30%)
    9 Game Trapezoid - Trapezoid game distribution (50%)
    10 Game Bowl - Bowl shaped game distribution (50%)
    11 Game Wedge - Wedge shaped game distribution (30%)
    12 Game Teat - Teat shaped game distribution (30%)

Thanks.
A big fan of JavaScript.
B
76
S
20
G
74
Posts: 2,251
Reputation: 46,476

Post » Wed Oct 12, 2016 5:38 pm

Nice to have some more rng options.
Makes me want to stay away from Vegas however.
Grats.
Image ImageImage
B
171
S
50
G
179
Posts: 8,382
Reputation: 113,458

Post » Mon Oct 17, 2016 1:16 am

question can this plugin deal with dynamic Ai situation based. As in if the Ai is almost dead intead of being a blood thristy attacker it should start to think about defend or using a heal from an ally or an item. as oppose to when it has 100% hp it should relie on attacking.

And what about making it a bit smarter as in if you are weak against a particular spell it should be thinking to use that but if you fully resist it as in if it use an attack and it didnt work on you the first time drop it ? and use a different number placement?

Because often times ive seen random number to alway choose one number and its irrating as hell like choose 1 2 3. so that 30% effective choice......1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 oh hi 3 back to 1111111. you can understand this fusteration.
B
52
S
24
G
6
Posts: 391
Reputation: 7,845

Post » Mon Oct 17, 2016 1:28 am

Gearworkdragon wrote:question can this plugin deal with dynamic Ai situation based. As in if the Ai is almost dead intead of being a blood thristy attacker it should start to think about defend or using a heal from an ally or an item. as oppose to when it has 100% hp it should relie on attacking.

And what about making it a bit smarter as in if you are weak against a particular spell it should be thinking to use that but if you fully resist it as in if it use an attack and it didnt work on you the first time drop it ? and use a different number placement?

Because often times ive seen random number to alway choose one number and its irrating as hell like choose 1 2 3. so that 30% effective choice......1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 oh hi 3 back to 1111111. you can understand this fusteration.


This plugin will only generate a random number; the AI is for you to manage in events. Depending on the distribution profile you select, it will produce a 'loaded' random number to fit that profile. Have a look at the demo if you're not sure / I'll try to answer if you have more questions.
A big fan of JavaScript.
B
76
S
20
G
74
Posts: 2,251
Reputation: 46,476

Post » Tue Dec 27, 2016 6:36 pm

Nice work Bender!
B
67
S
37
G
13
Posts: 241
Reputation: 12,760

Post » Tue Dec 27, 2016 6:51 pm

Cheers, @Unconnected!
A big fan of JavaScript.
B
76
S
20
G
74
Posts: 2,251
Reputation: 46,476

Post » Wed Dec 28, 2016 12:23 am

When installing it into the "Program Files\Construct 2\exporters\html5\Plugins" folder you have to move the contents of the "src" back one file in the file tree.

In other words you have to take the contents of "Src" out of the "Src" folder and place it where the "Src" folder is.

It took me a small bit to figure that out.
Works great too, Thanks again.
B
67
S
37
G
13
Posts: 241
Reputation: 12,760


Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 3 guests