Fórum gerar numero aleatorio #208591
22/01/2004
0
eu estou fazendo uma tela de proteção para a configuração do meu programa para que eu possa ter controle de quando foi acessado a tela de configuracao do sistema...... eu quero fazer isso pela data do sistema quando aumenta um dia ele troca a senha ... eu fiz um algoritmo que gera senha aleatoriamente mas eu uso a função [u:0089f61e04]Random[/u:0089f61e04] para isso mas nao pode ser um numero randomico gerado pela funcao se teria que se gerado por mim ai eu teria controle de que senha vai ser tal dia entao o usuario temque ligar para mim para poder obter a senha e com a funcao random ele la vai ter uma senha gerada e eu vou ter outra .... entendem .... eu quero fazer isso manualmente se algem conseguir m ajudar eu agradeço muito valew
olhem o meu codigo:
procedure TForm1.Button1Click(Sender: TObject); var i:integer; Dia, Mes, Ano : string; const str=´1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ´; max=12; begin senha:=´´; Dia := FormatDateTime(´DD´,date); Mes := FormatDateTime(´MM´,date); Ano := FormatDateTime(´yy´,date); for i:=1 to max do senha:=senha+str[random(length(str))+1]; Insert(dia,senha,4); Insert(mes,senha,8); Insert(ano,senha,12); edit1.Text := senha; end;
ai depois eu tenho que implementar para que a cada dia seja trocada automaticamente e se o usuario quiser entrar na configuração do sistema ele temque ligar para a empresa...
muito obrigado por estar lendo este tópico..
Zumbi
Curtir tópico
+ 0Posts
22/01/2004
Cebikyn
Gostei + 0
22/01/2004
Zumbi
Gostei + 0
22/01/2004
Cebikyn
Gostei + 0
23/01/2004
Wolverine
var
i:integer;
const
str=´1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ´;
max=6;
begin
Edit1.Text:=´´;
for i:=1 to max do
Edit1.Text:=Edit1.Text+str[random(length(str))+1];
end;
Gostei + 0
23/01/2004
Nigro
Crie um form com os seguintes objetos:
- Listbox1 com a fonte ´Courier New´
- Edit1 com Edit1.Text := 6 Numero de Dezenas
- Edit2 with Edit2.Text := 49 Valor Maximo
- Edit3 with Edit3.Text := 10 Numero de Jogos
- Button1 com onClick com o evento Button1Click abaixo
Isto criará 10 serie de jogos
com os numeros entre 1 e 49
Numeros não serão repetidos
vc poderá mudar os tres valores
procedure TForm1.Button1Click(Sender: TObject);
var
MyList: TStringList;
Times, I, Number: Integer;
cInt, cLen: string;
begin
// make the button disabled to prevent multiple clicks
Self.enabled := False;
// convert the highest number
Number := StrToInt(Edit2.Text);
// this creates the correct format-argument for every
// max-numbers (e.g. 49 , 120, 9999 ....)
cLen := IntToStr(length(trim(Edit2.text)) + 1);
MyList := TStringList.Create;
try
// first clear the Listbox
Listbox1.clear;
// here we start a new serie
for Times := 1 to StrToInt(Edit3.Text) do
begin
// we go thru this while-loop until the max-numbers
// are created. Not every loop creates an entry
// to the list because double numbers are ignored.
while MyList.Count < StrToInt(Edit1.Text) do
begin
// get a new random number
I := Random(Number);
if (I 0) then
begin
// cLen has the number of chars from max-number plus one
// e.g.
// if max-number is 49 cLen is 3
// if max-number is 111 cLen is 4
// if max-number is 9999 cLen is 5
// this formatting is needed for the correct
// sorting of all List-Entries
cInt := Format(´¬´ + cLen + ´.1d´, [I]);
// here we look at double entries and ignore it
if (MyList.IndexOf(cInt) < -1) then
continue;
// now we add a new randomnumber
MyList.Add(cInt);
end;
end;
cInt := ´´;
// max-numbers are created now we sort it
MyList.Sort;
// and put it all into Listbox
for I := 0 to MyList.Count - 1 do
cInt := cInt + MyList.Strings[I];
ListBox1.Items.Add(cInt);
// clear MyList for the next serie
MyList.clear;
end;
finally
MyList.Free;
end;
// make the button enable for the next click
Self.enabled := True;
end;
--------------------------------------------------------------------------------
Outra opção sem utilizar componentes visuais é:
type
{array of series of picks, used in Pick function}
TPick = array of array of integer;
function Pick (APicks, AMax, ASeries: integer): TPick;
var
I, J, Index: integer;
PickArray: array of integer;
begin
if (APicks = AMax) then
begin
raise Exception.Create (´Pick: Max available number should be larger than number of picks´);
end;
if (APicks < 1) then
begin
raise Exception.Create (´Pick: You should request at least one pick´);
end;
if (ASeries < 1) then
begin
raise Exception.Create (´Pick: You should request at least one series´);
end;
SetLength (Result, ASeries);
for I := Low (Result) to High (Result) do
begin
{populate AArray }
SetLength (PickArray, AMax);
for J := Low (PickArray) to High (PickArray) do
begin
PickArray [J] := J + 1;
end;
SetLength (Result [I], APicks);
for J := Low (Result [I]) to High (Result [I]) do
begin
Result [I, J] := 0;
while (Result [I, J] = 0) do
begin
Index := Random (AMax);
Result [I, J] := PickArray [Index];
PickArray [Index] := 0;
end;
end; {for J}
end; {for I}
end; {--Pick--}
Exemplo de Uso
var
APick: TPick;
begin
APick := Pick (6, 49, 10); {we need 10 series of 6/49 numbers}
...
Gostei + 0
23/01/2004
Zumbi
Gostei + 0
23/01/2004
Zumbi
legal seu programa que vc colocou!!!
mas se vc percebeu vc usa a função [u:d205c342ac]Randon[/u:d205c342ac]
while MyList.Count < StrToInt(Edit1.Text) do begin // get a new random number I := Random(Number); if (I 0) then begin // cLen has the number of chars from max-number plus one // e.g. // if max-number is 49 cLen is 3 // if max-number is 111 cLen is 4 // if max-number is 9999 cLen is 5
entaum eu naum posso usar isso pois naum tenho controle de que nº esta sendo gerado ...... pois eu vou ter a aplicação no cliente e todo dia muda a senha entaum a senha que gerar la vai terque ser a mesma que eu terei aqui na empresa.....e com a funcao random naum tem como fazer isso pois aqui vai gerar um numero e la vai gerar outro !!!!!!!!!
hehheeh entao se puder ver algo que que naum utilize a funcao random eu agradeço ....
velew pela ajuda!!!!!
Gostei + 0
23/01/2004
Nigro
Gostei + 0
26/01/2004
Zumbi
Gostei + 0
26/01/2004
Paulo_amorim
Acho boa a ideia dada pelo cebikyn
por que não tenta chegar a um numero ´randomico´ que vc cria?
seila, soma, divide, pega o MOD...ai vc pode complicar a vontade
Gostei + 0
26/01/2004
Paulo_amorim
Acho boa a ideia dada pelo cebikyn
por que não tenta chegar a um numero ´randomico´ que vc cria?
seila, soma, divide, pega o MOD...ai vc pode complicar a vontade
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)