JNIEXPORT jint JNICALL Java_org_simgrid_msg_RngStream_randInt(JNIEnv *env, jobject jrngstream, jint i, jint j) {
  RngStream rngstream = jrngstream_to_native(env, jrngstream);
  if (!rngstream)
    return 0;

  return (jint)RngStream_RandInt(rngstream, (int)i, (int)j);
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_resetNextSubstream(JNIEnv *env, jobject jrngstream) {
  RngStream rngstream = jrngstream_to_native(env, jrngstream);
  if (!rngstream)
    return;

  RngStream_ResetNextSubstream(rngstream);
}
JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_RngStream_randU01(JNIEnv *env, jobject jrngstream) {
  RngStream rngstream = jrngstream_to_native(env, jrngstream);
  if (!rngstream)
    return 0;

  return (jdouble)RngStream_RandU01(rngstream);
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_advanceState(JNIEnv *env, jobject jrngstream, jint e, jint g) {
  RngStream rngstream = jrngstream_to_native(env, jrngstream);
  if (!rngstream)
    return;

  RngStream_AdvanceState(rngstream, (long)e, (long)g);
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_setAntithetic(JNIEnv *env, jobject jrngstream, jboolean ja) {
  RngStream rngstream = jrngstream_to_native(env, jrngstream);
  if (!rngstream)
    return;

  if (ja == JNI_TRUE) {
    RngStream_SetAntithetic(rngstream,-1);
  }
  else {
    RngStream_SetAntithetic(rngstream,0);
  }
}
示例#6
0
JNIEXPORT jboolean JNICALL
Java_org_simgrid_msg_RngStream_setPackageSeed(JNIEnv *env, jobject jrngstream, jintArray jseed) {
  jint buffer[6];

  env->GetIntArrayRegion(jseed, 0, 6, buffer);

  RngStream rngstream = jrngstream_to_native(env, jrngstream);
  if (!rngstream)
    return JNI_FALSE;

  int result = RngStream_SetPackageSeed((unsigned long*)buffer);

  return result == -1 ? JNI_FALSE : JNI_TRUE;
}
JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_RngStream_setSeed(JNIEnv *env, jobject jrngstream, jintArray jseed) {
  jint buffer[6];

  env->GetIntArrayRegion(jseed, 0, 6, buffer);

  RngStream rngstream = jrngstream_to_native(env, jrngstream);
  if (!rngstream)
    return JNI_FALSE;

  // The C API expects unsigned long which are wider than int on LP64.
  // We need to convert:
  unsigned long seed[6];
  for (int i = 0; i != 6; ++i)
    seed[i] = buffer[i];

  int result = RngStream_SetSeed(rngstream, seed);

  return result == -1 ? JNI_FALSE : JNI_TRUE;
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_nativeFinalize(JNIEnv *env, jobject jrngstream) {
  RngStream rngstream = jrngstream_to_native(env, jrngstream);
  RngStream_DeleteStream(&rngstream);
  env->SetLongField(jrngstream, jrngstream_bind, (intptr_t)nullptr);
}