matthias-research / pages

My web page containing all the demos from my youtube channel "Ten Minute Physics" www.youtube.com/c/TenMinutePhysics
655 stars 136 forks source link

The hash function has a problem with negative cell index #26

Open lyd405121 opened 1 year ago

lyd405121 commented 1 year ago

Background

fluid-error

The problem

nTableSize = 2000 nX = 1 nY = 1 nZ = 1 h1 = abs((nX 92837111) ^ (nY 689287499) ^ (nZ 283923481)) % nTableSize h2 = (73856093 nX + 19349663 nY + 83492791 nZ) % nTableSize print("----------hash-function for (x=1 y=1 z=1)-----------") print("ten minutes physics:", h1) print("interactive-graphics:",h2) print("")

nX = 1 nY = 1 nZ = -1 h1 = abs((nX 92837111) ^ (nY 689287499) ^ (nZ 283923481)) % nTableSize h2 = (73856093 nX + 19349663 nY + 83492791 nZ) % nTableSize print("----------hash-function for (x=1 y=1 z=-1)-----------") print("ten minutes physics:", h1) print("interactive-graphics:",h2)


- Here is the print result 
```python
----------hash-function for (x=1 y=1 z=1)-----------
ten minutes physics: 1621
interactive-graphics: 547

----------hash-function for (x=1 y=1 z=-1)-----------
ten minutes physics: 1621
interactive-graphics: 965

Solution

fluid-right

At last