Random(Random(Random(x)))

Share your advanced PureBasic knowledge/code with the community.
User avatar
SPH
Enthusiast
Enthusiast
Posts: 593
Joined: Tue Jan 04, 2011 6:21 pm

Random(Random(Random(x)))

Post by SPH »

PB6.20 OR LESS

The benefits of random(random(...(x))) :wink:

F1 to decrease the number of Randoms
F2 to increase the number of Randoms
Right and left mouse clicks to shoot and new target

Code: Select all

InitSprite()
InitMouse()
InitKeyboard()

OpenWindow(0, 0, 0, 800, 800, "Pan!", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 800, 800)

CreateSprite(0,200,200)
StartDrawing(SpriteOutput(0))
DrawingMode(#PB_2DDrawing_Outlined)      
LineXY(99,0,99,200,RGB(0,0,20))
LineXY(0,99,200,99,RGB(0,0,20))
LineXY(101,0,101,200,RGB(0,0,20))
LineXY(0,101,200,101,RGB(0,0,20))
Circle(100,100,80,RGB(0,0,20))
Circle(100,100,40,RGB(0,0,20))
StopDrawing()

CreateSprite(1, 800, 800)
StartDrawing(SpriteOutput(1))
DrawingMode(#PB_2DDrawing_Default)      
For i= 400 To 10 Step -50
  If u=1
    rvb=RGB(255,50,50)
  Else
    rvb=RGB(250,250,250)
  EndIf
  u+1
  u%2
  Circle(400, 400, i, rvb)
Next
LineXY(0,400,800,400,RGB(0,0,0))
LineXY(400,0,400,800,RGB(0,0,0))
StopDrawing() 

Dim plomb_x(9)
Dim plomb_y(9)
fire=0
cmb=0

Repeat
  
  Repeat
    Event = WindowEvent()
    Select Event
      Case #PB_Event_CloseWindow : End 
    EndSelect
  Until Event = 0
  
  DisplaySprite(1, 0, 0)
  ExamineMouse()
  MX=MouseX()
  MY=MouseY()
  
  DisplayTransparentSprite(0,MX,MY)
  If MouseButton(2)
    fire=0
  EndIf
  
    If MouseButton(1) And fire=0
    
    fire=1
    
    For i=1 To 9
      x=Random(400)
      y=Random(400)
      For u=1 To cmb
        x=Random(x)
        y=Random(y)
      Next
      
      plomb_x(i)=mx+100+x*(Random(1)*2-1)
      plomb_y(i)=my+100+y*(Random(1)*2-1)
    Next
  EndIf
  
  If fire=1
    StartDrawing(ScreenOutput())
    DrawingMode(#PB_2DDrawing_Default)      
    For i=1 To 9
      Circle(plomb_x(i),plomb_y(i),12,RGB(0,0,0))
    Next
    StopDrawing() 
  EndIf
  
  StartDrawing(ScreenOutput())
    DrawingMode(#PB_2DDrawing_Default)      
    
    a$=""
    For i=0 To cmb
      a$+"Random("
    Next
    
    DrawText(50, 420, a$)

    StopDrawing() 
  
  FlipBuffers()
  ExamineKeyboard()
If KeyboardPushed(#PB_Key_F1)  
  cmb-1
  If cmb<0
    cmb=0
  EndIf
  Delay(200)
EndIf

If KeyboardPushed(#PB_Key_F2)  
  cmb+1
  Delay(200)
EndIf

Until Event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)


!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits