本文整理了Java中org.jruby.Ruby.getRandomClass
方法的一些代码示例,展示了Ruby.getRandomClass
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ruby.getRandomClass
方法的具体详情如下:
包路径:org.jruby.Ruby
类名称:Ruby
方法名:getRandomClass
暂无
代码示例来源:origin: org.jruby/jruby-core
private static RandomType tryGetRandomType(ThreadContext context, IRubyObject obj) {
if (obj.equals(context.runtime.getRandomClass())) return getDefaultRand(context);
if (obj instanceof RubyRandom) return ((RubyRandom) obj).random;
return null;
}
代码示例来源:origin: org.jruby/jruby-complete
private static RandomType tryGetRandomType(ThreadContext context, IRubyObject obj) {
if (obj.equals(context.runtime.getRandomClass())) return getDefaultRand(context);
if (obj instanceof RubyRandom) return ((RubyRandom) obj).random;
return null;
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
public static double randomReal(ThreadContext context, IRubyObject obj) {
RandomType random = null;
if (obj.equals(context.runtime.getRandomClass())) {
random = getDefaultRand(context);
}
if (obj instanceof RubyRandom) {
random = ((RubyRandom) obj).random;
}
if (random != null) {
return random.genrandReal();
}
double d = RubyNumeric.num2dbl(Helpers.invoke(context, obj, "rand"));
if (d < 0.0 || d >= 1.0) {
throw context.runtime.newRangeError("random number too big: " + d);
}
return d;
}
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
public static double randomReal(ThreadContext context, IRubyObject obj) {
RandomType random = null;
if (obj.equals(context.runtime.getRandomClass())) {
random = getDefaultRand(context);
}
if (obj instanceof RubyRandom) {
random = ((RubyRandom) obj).random;
}
if (random != null) {
return random.genrandReal();
}
double d = RubyNumeric.num2dbl(Helpers.invoke(context, obj, "rand"));
if (d < 0.0 || d >= 1.0) {
throw context.runtime.newRangeError("random number too big: " + d);
}
return d;
}
代码示例来源:origin: org.jruby/jruby-complete
@SuppressWarnings("deprecation")
public static IRubyObject srandCommon(ThreadContext context, IRubyObject recv, IRubyObject newSeed) {
RandomType defaultRand = getDefaultRand(context);
IRubyObject previousSeed = defaultRand.getSeed();
defaultRand = new RandomType(newSeed);
context.runtime.setDefaultRand(defaultRand);
((RubyRandom) (context.runtime.getRandomClass()).getConstant("DEFAULT")).setRandomType(defaultRand);
return previousSeed;
}
代码示例来源:origin: org.jruby/jruby-core
@SuppressWarnings("deprecation")
public static IRubyObject srandCommon(ThreadContext context, IRubyObject recv, IRubyObject newSeed) {
RandomType defaultRand = getDefaultRand(context);
IRubyObject previousSeed = defaultRand.getSeed();
defaultRand = new RandomType(newSeed);
context.runtime.setDefaultRand(defaultRand);
((RubyRandom) (context.runtime.getRandomClass()).getConstant("DEFAULT")).setRandomType(defaultRand);
return previousSeed;
}
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
public static IRubyObject srandCommon(ThreadContext context, IRubyObject recv,
IRubyObject newSeed) {
RandomType defaultRand = getDefaultRand(context);
IRubyObject previousSeed = defaultRand.getSeed();
defaultRand = new RandomType(newSeed);
context.runtime.setDefaultRand(defaultRand);
if (context.runtime.is1_9()) {
((RubyRandom) (context.runtime.getRandomClass())
.getConstant("DEFAULT")).setRandomType(defaultRand);
}
return previousSeed;
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
public static IRubyObject srandCommon(ThreadContext context, IRubyObject recv,
IRubyObject newSeed) {
RandomType defaultRand = getDefaultRand(context);
IRubyObject previousSeed = defaultRand.getSeed();
defaultRand = new RandomType(newSeed);
context.runtime.setDefaultRand(defaultRand);
if (context.runtime.is1_9()) {
((RubyRandom) (context.runtime.getRandomClass())
.getConstant("DEFAULT")).setRandomType(defaultRand);
}
return previousSeed;
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
@JRubyMethod(name = "shuffle!", optional = 1, compat = RUBY1_9)
public IRubyObject shuffle_bang(ThreadContext context, IRubyObject[] args) {
modify();
IRubyObject randgen = context.runtime.getRandomClass();
if (args.length > 0) {
IRubyObject hash = TypeConverter.checkHashType(context.runtime, args[args.length - 1]);
if (!hash.isNil()) {
IRubyObject argRandgen = ((RubyHash) hash).fastARef(context.runtime.newSymbol("random"));
if (argRandgen != null) {
randgen = argRandgen;
}
}
}
int i = realLength;
try {
while (i > 0) {
int r = (int) (RubyRandom.randomReal(context, randgen) * i);
IRubyObject tmp = eltOk(--i);
values[begin + i] = eltOk(r);
values[begin + r] = tmp;
}
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
}
return this;
}
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
@JRubyMethod(name = "shuffle!", optional = 1, compat = RUBY1_9)
public IRubyObject shuffle_bang(ThreadContext context, IRubyObject[] args) {
modify();
IRubyObject randgen = context.runtime.getRandomClass();
if (args.length > 0) {
IRubyObject hash = TypeConverter.checkHashType(context.runtime, args[args.length - 1]);
if (!hash.isNil()) {
IRubyObject argRandgen = ((RubyHash) hash).fastARef(context.runtime.newSymbol("random"));
if (argRandgen != null) {
randgen = argRandgen;
}
}
}
int i = realLength;
try {
while (i > 0) {
int r = (int) (RubyRandom.randomReal(context, randgen) * i);
IRubyObject tmp = eltOk(--i);
values[begin + i] = eltOk(r);
values[begin + r] = tmp;
}
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
}
return this;
}
代码示例来源:origin: org.jruby/jruby-core
@JRubyMethod(name = "shuffle!", optional = 1)
public IRubyObject shuffle_bang(ThreadContext context, IRubyObject[] args) {
modify();
IRubyObject randgen = context.runtime.getRandomClass();
if (args.length > 0) {
IRubyObject hash = TypeConverter.checkHashType(context.runtime, args[args.length - 1]);
if (!hash.isNil()) {
IRubyObject[] rets = ArgsUtil.extractKeywordArgs(context, (RubyHash) hash, "random");
if (rets[0] != UNDEF) randgen = rets[0];
}
}
int i = realLength;
int len = i;
try {
while (i > 0) {
int r = (int) RubyRandom.randomLongLimited(context, randgen, i - 1);
if (len != realLength) { // || ptr != RARRAY_CONST_PTR(ary)
throw context.runtime.newRuntimeError("modified during shuffle");
}
T tmp = eltOk(--i);
eltSetOk(i, eltOk(r));
eltSetOk(r, tmp);
}
} catch (ArrayIndexOutOfBoundsException ex) {
throw concurrentModification(context.runtime, ex);
}
return this;
}
代码示例来源:origin: org.jruby/jruby-complete
@JRubyMethod(name = "shuffle!", optional = 1)
public IRubyObject shuffle_bang(ThreadContext context, IRubyObject[] args) {
modify();
IRubyObject randgen = context.runtime.getRandomClass();
if (args.length > 0) {
IRubyObject hash = TypeConverter.checkHashType(context.runtime, args[args.length - 1]);
if (!hash.isNil()) {
IRubyObject[] rets = ArgsUtil.extractKeywordArgs(context, (RubyHash) hash, "random");
if (rets[0] != UNDEF) randgen = rets[0];
}
}
int i = realLength;
int len = i;
try {
while (i > 0) {
int r = (int) RubyRandom.randomLongLimited(context, randgen, i - 1);
if (len != realLength) { // || ptr != RARRAY_CONST_PTR(ary)
throw context.runtime.newRuntimeError("modified during shuffle");
}
T tmp = eltOk(--i);
eltSetOk(i, eltOk(r));
eltSetOk(r, tmp);
}
} catch (ArrayIndexOutOfBoundsException ex) {
throw concurrentModification(context.runtime, ex);
}
return this;
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
@JRubyMethod(name = "sample", optional = 2, compat = RUBY1_9)
public IRubyObject sample(ThreadContext context, IRubyObject[] args) {
try {
IRubyObject randgen = context.runtime.getRandomClass();
if (args.length == 0) {
if (realLength == 0)
代码示例来源:origin: org.jruby/jruby-complete
unpack();
try {
IRubyObject randgen = context.runtime.getRandomClass();
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
@JRubyMethod(name = "sample", optional = 2, compat = RUBY1_9)
public IRubyObject sample(ThreadContext context, IRubyObject[] args) {
try {
IRubyObject randgen = context.runtime.getRandomClass();
if (args.length == 0) {
if (realLength == 0)
代码示例来源:origin: org.jruby/jruby-core
unpack();
try {
IRubyObject randgen = context.runtime.getRandomClass();
内容来源于网络,如有侵权,请联系作者删除!