Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#2931 closed defect (fixed)

[PATCH] random numbers for AI

Reported by: mimo Owned by:
Priority: Should Have Milestone: Alpha 18
Component: UI & Simulation Keywords: patch
Cc: Patch:

Description

Presently, javascript has no seeded random generator, so the sequence of random numbers is always the same. That's really problematic for the AI. Here is a patch to prevent this situation: it transfers to the AI the seed defined at initialization (mainly for random map generation), and adds some entropy when we initialize the shared AI component by doing n dummy calls to the generator (n being a function of the seed). In addition, it corrects a bug where the wrong seed was used when defined by autostart.

The next step will be to use a true seeded algorithm, instead of this hand-made initialization.

Attachments (2)

seed.diff (7.2 KB ) - added by mimo 9 years ago.
seed.2.diff (5.8 KB ) - added by mimo 9 years ago.

Download all attachments as: .zip

Change History (5)

by mimo, 9 years ago

Attachment: seed.diff added

comment:1 by agentx, 9 years ago

Here is a good and fast implementation of the Mersenne Twister algorithm. Licence: LGPL

http://simjs.com/random.html#the-random-library

comment:2 by mimo, 9 years ago

After discussion with leper and yves on IRC, it happens that we already have an implementation of a seeded random generator, but its seed initialisation was missing. So the previous patch is now modified accordingly.

by mimo, 9 years ago

Attachment: seed.2.diff added

comment:3 by mimo, 9 years ago

Keywords: review removed
Milestone: BacklogAlpha 18
Resolution: fixed
Status: newclosed

fixed in r15973

Last edited 9 years ago by mimo (previous) (diff)
Note: See TracTickets for help on using tickets.