UnderwareDESIGN

PlayBASIC => Resources => Source Codes => Topic started by: XpMe_v1.2 on October 27, 2005, 03:25:09 PM

Title: GetRandomFloatValue
Post by: XpMe_v1.2 on October 27, 2005, 03:25:09 PM
This may be useful for someone.
`----------------------------------------------------------------
Text 333,222, Str$( GetRandomFloatValue(0,500 ,0,99) )
Sync
WaitKey
`-----------------will get a float number from 0.0 to 500.99
Function GetRandomFloatValue(Lmin ,Lmax ,Rmin ,Rmax)
EndFunction Val(Str$(RndRange(Lmin,Lmax)) +"."+ Str$(RndRange(Rmin ,Rmax)) )
`----------------------------------------------------------------
Title: GetRandomFloatValue
Post by: XpMe_v1.2 on October 27, 2005, 03:55:17 PM
If a Negative is needed then try this one.

Text 233,122, Str$( GetRandomFloatValue( 0 , 500 ,35 ,   99 , -1) )
Text 233,172, Str$( GetRandomFloatValue(70 , 500 , 0 , 4399 ,  0) )
Print ""
Print "" : Print GetRandomFloatValue(0   ,  500 , 0 ,   99 , -1)
Print "" : Print GetRandomFloatValue(0   , 2500 , 0 ,   99 ,  0)
Print "" : Print GetRandomFloatValue(240 ,  800 , 0 , 1659 , -1)
Sync
WaitKey
`----------------- will get a float number from 0.0 to 500.99
`----------------- or lower numbers or higher numbers
`----------------- add a  -1 to the end and get negative random numbers
Function GetRandomFloatValue(Lmin ,Lmax ,Rmin ,Rmax, minus)
Low$="" : If minus = -1 Then Low$ = "-"
EndFunction Val(Low$ + Str$(RndRange(Lmin,Lmax)) +"."+ Str$(RndRange(Rmin ,Rmax)))
`----------------------------------------------------------------
Title: Re: GetRandomFloatValue
Post by: kevin on June 22, 2007, 12:10:43 PM
 To Get a Random float value use the # postfix to select the float version of the RND number generator.


[pbcode]

 Print Rnd#(100)
 Print RndRange#(100,200)

Sync
Waitkey

[/pbcode]