vb 2017 : random 2.0

Status
Niet open voor verdere reacties.

blua tigro

Gebruiker
Lid geworden
21 apr 2009
Berichten
48
dit is handig als je n langere herhaaltijd wil

uitbreidingen en verbeteringen zijn welkom

Code:
public class random2
    private const size as integer = 32
    private rndtab(size-1) as double
    private i1 as integer
    private i2 as integer

    public sub new()
        init_rnd(now.ticks.tostring)
    end sub
  
    public sub new(a as string)
        init_rnd(a)
    end sub

    public sub init_rnd(a as string)
        dim i as integer
        dim d as double
        dim tel as integer

        randomize( -1 )
        for tel = 0 to size - 1
            i = tel mod a.length
            d = math.pi/asc(a.substring(i,1))
            rndtab(tel)=(rnd()*d)mod 1.0
        next tel
     
        i1 = size \ 2
        i2 = size \ 3

        for tel = 0 to size * 5
            get_next_double()
        next tel

        randomize(rnd(-get_next_single()))
    end sub

    public function get_next_double()as double
        i1=(i1+1)mod size
        i2=(i2+1)mod size
        
        rndtab(i1)=+=rndtab(i2)+rnd()
        rndtab(i1)=rndtab(i1)mod 1.0

        return rndtab(i1)
    end function

    public function get_next_integer(low as integer _
    , high as integer ) as integer
        return cint(get_next_double()*(high-low+1.0)+low)
    end function

    public function get_next_char()as string
        return asc(get_next_integer(0,255))
    end function

    public function get_next_gaus( average as double _
    , d as double )
    ''for a randomnumber whit normaldistrebution
        dim x1 as double = get_next_double()
        dim x2 as double = get_next_double()
        dim x3 as double = 2 * math.log( x1 )
        x3 = math.sqrt( math.abs( x3 ) )
        x3 = x3 * math.cos( x2 * math.pi * 2 )
        return x3 * d + average
    end function

end class
 
Status
Niet open voor verdere reacties.
Steun Ons

Nieuwste berichten

Terug
Bovenaan Onderaan