Skip to content

Commit bb4164c

Browse files
Added NFT Chance Array math
1 parent d58109c commit bb4164c

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

chronological-updates.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,45 @@ If your keepers are not kicking off, run through this checklist to find out why.
8888
## Metamask Troubleshooting while using Gitpod
8989

9090
- Remember if you are using gitpod then you cannot connect your local hardhat node with metamask. To resolve this you can use vs code or testnets instead of local node.
91+
92+
93+
--------
94+
95+
# Lesson 14
96+
97+
## Math on NFT Chance Array
98+
99+
The ```getBreedFromModdedRng()``` function in RandomIpfsNft.sol gets the math wrong.
100+
101+
line 104,
102+
```solidity
103+
if (moddedRng >= cumulativeSum && moddedRng < cumulativeSum + chanceArray[i]) {
104+
return Breed(i);
105+
}
106+
cumulativeSum = cumulativeSum + chanceArray[i];
107+
```
108+
needs to be changed to
109+
```solidity
110+
if (moddedRng >= cumulativeSum && moddedRng < chanceArray[i]) {
111+
return Breed(i);
112+
}
113+
cumulativeSum = chanceArray[i];
114+
```
115+
116+
The chanceArray[] array already has a cumulative probability distribution, no need to keep adding cumulativeSum to it.
117+
118+
According to the current algorithm:
119+
```
120+
moddedRng produced is between 0 and 99
121+
chanceArray=[10,30,100]
122+
```
123+
```
124+
PUG is produced if moddedRng is between [0,10) = span of 10
125+
SHIBA is produce if moddedRng is between [10,40) = span of 30
126+
BERNARD is produced if moddedRng is between [40,140] = span of 60 (since moddedRng<100)
127+
```
128+
So the actual probabilities according to the current algo is
129+
``` [10%,30%,60%] ```
130+
and not
131+
``` [10%,20%,70%]```
132+
as would be expected from a proper cumulative probability distribution function.

0 commit comments

Comments
 (0)