Advertisement
nanerbk8

Sorteador simples de 2 números diferentes com limite máximo.

Jan 24th, 2013
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.79 KB | None | 0 0
  1. unit unit_sorteio;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls, Spin, Grids, XPMan, ExtCtrls;
  8.  
  9. type
  10.   Tfrm_sorteador_tuneup = class(TForm)
  11.     btn_sort: TButton;
  12.     Label2: TLabel;
  13.     Label3: TLabel;
  14.     spin_max: TSpinEdit;
  15.     XPManifest1: TXPManifest;
  16.     label_sort1: TLabel;
  17.     label_sort2: TLabel;
  18.     Image1: TImage;
  19.     Label1: TLabel;
  20.     procedure btn_sortClick(Sender: TObject);
  21.     procedure FormCreate(Sender: TObject);
  22.   private
  23.     { Private declarations }
  24.   public
  25.     { Public declarations }
  26.   end;
  27.  
  28. var
  29.   frm_sorteador_tuneup: Tfrm_sorteador_tuneup;
  30.  
  31. implementation
  32.  
  33. uses Math;
  34.  
  35. {$R *.dfm}
  36.  
  37. procedure Tfrm_sorteador_tuneup.btn_sortClick(Sender: TObject);
  38.   //VARIAVEIS LOCAIS
  39.   var max: Integer;
  40.   var res1: String;
  41.   var res2: String;
  42. begin
  43.   max:=spin_max.Value;
  44.   //------------SORTEIO1-------
  45.   while res1<'1' do //REPETE O SORTEIO ATE QUE O NUMERO SEJA MAIOR QUE ZERO E VALIDO
  46.     begin
  47.       Randomize;
  48.       res1:=FormatFloat('0', Random(max+1)); //GERA UM NUMERO ALEATORIO ENTRE 1 E O VALOR MAXIMO
  49.     end;
  50.   label_sort1.Caption:=res1; //DEFINE O PRIMEIRO GANHADOR
  51.   //----SORTEIO2-------
  52.   while res2<'1' do //REPETE O SORTEIO ATE QUE O NUMERO SEJA MAIOR QUE ZERO E VALIDO
  53.     begin
  54.       Randomize;
  55.       repeat res2:=FormatFloat('0', Random(max+1)); //GERA UM NUMERO ALEATORIO ENTRE 1 E O VALOR MAXIMO
  56.       until res2<>res1; //REPETE O SORTEIO SE O FOR O MESMO GANHADOR
  57.     end;
  58.   label_sort2.Caption:=res2; // DEFINE SEGUNDO GANHADOR
  59.   end;
  60. procedure Tfrm_sorteador_tuneup.FormCreate(Sender: TObject);
  61. begin
  62.   Randomize; // CONTROLE DO RANDOMSEED
  63. end;
  64. end.
  65.  
  66. You can download full software and code at http://www.mediafire.com/?7oezhtu58g0ga - PASSWORD: tecdicas
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement