-
Aug 28th, 2017, 04:43 AM
#1
Thread Starter
Junior Member
vb 2017 : random 2.0
for if you need a randomgenerator
whit longer repeattime
feel free to use
extensions and inprovements are welkome
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 ) 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
-
Aug 29th, 2017, 03:38 AM
#2
Thread Starter
Junior Member
Re: vb 2017 : random 2.0
i made a mistace
must be :
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 chr(get_next_integer(0,255))
end function
public function get_next_string(l as integer)as string
dim uit as string = ""
dim i as integer
for i = 1 to l
uit &= get_next_char()
next i
return uit
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|