Random(Random(Random(x)))

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Avatar de l’utilisateur
SPH
Messages : 4969
Inscription : mer. 09/nov./2005 9:53

Random(Random(Random(x)))

Message par SPH »

PB6.20 ou moins

F1 : pour réduire les "Random"
F2 : pour augmenter les "Random"
Souris boutons G et D : tir et changement de cible.

A quoi sert ce code ? A vous faire comprendre ce qu'un Random(Random(Randomx))) peut faire.
Après, à vous d'en tirer partie. :twisted:

Code : Tout sélectionner

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 ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.12LTS- 64 bits
Mesa
Messages : 1131
Inscription : mer. 14/sept./2011 16:59

Re: Random(Random(Random(x)))

Message par Mesa »

Interessant, je ne conaissais pas ce truc.

M.
Avatar de l’utilisateur
venom
Messages : 3155
Inscription : jeu. 29/juil./2004 16:33
Localisation : Klyntar
Contact :

Re: Random(Random(Random(x)))

Message par venom »

Trop random.... Je passe mon tour




:lol:





@++
Windows 10 x64, PureBasic 5.73 x86 & x64
GPU : radeon HD6370M, CPU : p6200 2.13Ghz
Avatar de l’utilisateur
SPH
Messages : 4969
Inscription : mer. 09/nov./2005 9:53

Re: Random(Random(Random(x)))

Message par SPH »

PS : mon anim simule un tir de chevrotine (il y a de mémoire 9 plombs gros comme des petits pois dans chaque cartouche)

Venom : plus il y a de random, plus tu te rapproches de 0

Code : Tout sélectionner

max=1000
cmb=5

x=0
For i=1 To cmb
  x+Random(max)
Next
x/cmb
Debug "1 Random : "+Str(x)+"/"+Str(max)
;;;;;;

x=0
For i=1 To cmb
  x+Random(Random(max))
Next
x/cmb
Debug "2 Random : "+Str(x)+"/"+Str(max)
;;;;;;

x=0
For i=1 To cmb
  x+Random(Random(Random(max)))
Next
x/cmb
Debug "3 Random : "+Str(x)+"/"+Str(max)
;;;;;;

x=0
For i=1 To cmb
  x+Random(Random(Random(Random(max))))
Next
x/cmb
Debug "4 Random : "+Str(x)+"/"+Str(max)
;;;;;;

x=0
For i=1 To cmb
  x+Random(Random(Random(Random(Random(max)))))
Next
x/cmb
Debug "5 Random : "+Str(x)+"/"+Str(max)
;;;;;;

x=0
For i=1 To cmb
  x+Random(Random(Random(Random(Random(Random(max))))))
Next
x/cmb
Debug "6 Random : "+Str(x)+"/"+Str(max)
;;;;;;

1 Random : 549/1000
2 Random : 134/1000
3 Random : 232/1000
4 Random : 74/1000
5 Random : 61/1000
6 Random : 6/1000
:twisted:

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.12LTS- 64 bits
Répondre