Date: 02-16-2022
Return to Index
created by gbSnippets
'The PowerBASIC RND function can generate a number between 0-1,
'or an integer between a pair of upper/lower values.
'Primary Code:
Randomize Timer 'common way to provide seed value that changes with each run
iResult& = Rnd(Lo,Hi) 'return value is Lo to Hi, inclusive
x! = Rnd 'return value: 0 to <1
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As DWord
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
Local iResult&, x!
Randomize Timer
iResult& = Rnd(100,200)
MsgBox "Random number between 100-200: " + Str$(iResult&)
x! = Rnd
MsgBox "Random number 0 to <1: " + Str$(x!)
End If
End Function
'gbs_00197
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm