Thanks

15 posts
• Page **1** of **2** • **1**, 2

Two ways -

First way won't give you exact distribution as a whole, but rather a 40/60% chance per array element.

Array for each element set instance variable*random* floor(random(10)

If*random* < 6, set element at CurX, CurY to "componentA"

If*random* >= 6, set element at CurX, CurY to "componentB"

oosyrag 2013-03-18 23:17:46

First way won't give you exact distribution as a whole, but rather a 40/60% chance per array element.

Array for each element set instance variable

If

If

Mistakes were made.

**Posts:**1,581**Reputation:**60,303

B

49
S

24
G

107
**Posts:**1,581**Reputation:**60,303

B

49
S

24
G

107
**Posts:**176**Reputation:**4,419

B

13
S

5
G

4
[QUOTE=Whiteclaws] You shall fill the array with "1" values and then you shall add a ramdomly positionned "2" in that same array 60 times ...[/QUOTE]

When filling with "2"s you would run into the problem that random filling would hit other already filled in "2"s in the process, so you'd have to loop some unnecessary times till you managed to find a free place for all "2".

Easier way that is random and still obtains a 40/60-distribution:

[your trigger]

chance = 0.4

elementsA = 0

elements = 0

- empty event : set elements = array.height*array.width*array.depth

set elementsA = elements * chance

- array for each xyz:

-- system compare: random(1) less or equal elementsA/elements: set at (array.curx, array.cury ,array.curz) = A

substract 1 from elementsA

substract 1 from elements

-- else: set at (array.curx, array.cury ,array.curz) = B

substract 1 from elements

examplatory runthrough what it does:

4 places: oooo

Let's sayA has a chance of 0.75. Elements is 4, so elementsA is 3 -> we get a chance of 3/4.

for first place the system rolls: rand(0) < 3/4 ->

Aooo

A's chance is now 2/3 (since elementsA was substracted by 1 as well as elements)

for the second place the system rolls a 0.54 ->

AAoo

A's chance is now 1/2

now the system rolls 0.8 ->

AABo

for the last roll the chance for A is 1/1 ->

AABAmindfaQ 2013-11-05 01:21:35

When filling with "2"s you would run into the problem that random filling would hit other already filled in "2"s in the process, so you'd have to loop some unnecessary times till you managed to find a free place for all "2".

Easier way that is random and still obtains a 40/60-distribution:

[your trigger]

chance = 0.4

elementsA = 0

elements = 0

- empty event : set elements = array.height*array.width*array.depth

set elementsA = elements * chance

- array for each xyz:

-- system compare: random(1) less or equal elementsA/elements: set at (array.curx, array.cury ,array.curz) = A

substract 1 from elementsA

substract 1 from elements

-- else: set at (array.curx, array.cury ,array.curz) = B

substract 1 from elements

examplatory runthrough what it does:

4 places: oooo

Let's sayA has a chance of 0.75. Elements is 4, so elementsA is 3 -> we get a chance of 3/4.

for first place the system rolls: rand(0) < 3/4 ->

Aooo

A's chance is now 2/3 (since elementsA was substracted by 1 as well as elements)

for the second place the system rolls a 0.54 ->

AAoo

A's chance is now 1/2

now the system rolls 0.8 ->

AABo

for the last roll the chance for A is 1/1 ->

AABA

Visual Novel 'Engine' in 100 Events

if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review

if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review

**Posts:**787**Reputation:**3,786

B

22
S

9
G

1
15 posts
• Page **1** of **2** • **1**, 2

## Who is online |

Users browsing this forum: No registered users and 7 guests |