prevent games reset at the same time from all having the same seed by

passing rand()'s seed from java world rather than using current
seconds.
This commit is contained in:
Eric House 2014-07-15 07:32:57 -07:00
parent 467477843b
commit ddd1ef70b6
2 changed files with 8 additions and 6 deletions

View file

@ -478,7 +478,7 @@ typedef struct _JNIState {
JNIEXPORT jint JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_initJNI
( JNIEnv* env, jclass C, int jniGlobalPtr )
( JNIEnv* env, jclass C, int jniGlobalPtr, jint seed )
{
/* Why am I doing this twice? */
/* struct timeval tv; */
@ -494,9 +494,8 @@ Java_org_eehouse_android_xw4_jni_XwJNI_initJNI
MPASSIGN( state->mpool, mpool );
globals->vtMgr = make_vtablemgr(MPPARM_NOCOMMA(mpool));
XP_U32 secs = getCurSeconds( env );
XP_LOGF( "initing srand with %d", secs );
srandom( secs );
XP_LOGF( "%s: initing srand with %d", __func__, seed );
srandom( seed );
return (jint) state;
}

View file

@ -21,6 +21,7 @@
package org.eehouse.android.xw4.jni;
import org.eehouse.android.xw4.DbgUtils;
import org.eehouse.android.xw4.Utils;
import android.graphics.Rect;
@ -87,8 +88,10 @@ public class XwJNI {
// Game methods
public static int initJNI()
{
return initJNI( getJNI().m_ptr );
int seed = Utils.nextRandomInt();
return initJNI( getJNI().m_ptr, seed );
}
public static native void game_makeNewGame( int gamePtr,
CurGameInfo gi,
UtilCtxt util,
@ -374,7 +377,7 @@ public class XwJNI {
// Private methods -- called only here
private static native int initGlobals();
private static native void cleanGlobals( int ptr );
private static native int initJNI( int jniState );
private static native int initJNI( int jniState, int seed );
private static native void dict_ref( int dictPtr );
private static native void dict_unref( int dictPtr );
private static native boolean dict_getInfo( int jniState, byte[] dict,