SWIG Funkion realiseren
-
Hallo,
ich wollte die folde C-Funktion mit SWIG in Ruby nutzbar machen, aber leider bekomme ich es nicht zum laufen.float gen_random(int *last, float max, int IM, int IA, int IC) { *last = (*last * IA + IC) % IM; return (max * *last / (float)IM); }
und die next Funktion habe ich folgendermaßen geändert:
require 'fastac' ... def next(max) # (max * (@last = (@last * @ia + @ic) % @im)) / @im Fastac.gen_random(@last, max, @im, @ia, @ic) end ...
und wenn ich das ganze ausführe bekomme ich folgenden Fehler:
$ ruby gen_random.rb gen_random.rb:12:in `gen_random': Expected argument 0 of type int *, but got Fixnum 42 (TypeError) in SWIG method 'gen_random' from gen_random.rb:12:in `next' from gen_random.rb:18 from gen_random.rb:17:in `times' from gen_random.rb:17
Was mache ich Falsch?
Vollständiger RUBY Code ohne C Funktion:
class Random def initialize(init, im=139968, ia=3877, ic=29573) @last = init @im = im @ia = ia @ic = ic end def next(max) (max * (@last = (@last * @ia + @ic) % @im)) / @im end end v = Random.new(42.0) 10.times do puts v.next(1.0) end