سلام
کد بزنامه ای که یک عدد تصادفی تولید کند
با تشکر
رامین
Printable View
سلام
کد بزنامه ای که یک عدد تصادفی تولید کند
با تشکر
رامین
چرا از تابع Random دلفی استفاده نمیکنی؟
سلام
در صورت امکان بشتر توضیح دهید
رامین
:shock:نقل قول:
نوشته شده توسط رامین.
نگاه کنید به راهنمای دلفی :)
delphi help
Random function :arrow:
Randomize procedure :arrow:
Delphi syntax:
function Random [ ( Range: Integer) ];
Description
In Delphi code, Random returns a random number within the range 0 <= X < Range. If Range is not specified, the result is a real-type random number within the range
0 <= X < 1.
To initialize the random number generator, add a single call Randomize or assign a value to the RandSeed variable before making any calls to Random.
var
I: Integer;
begin
Randomize;
for I := 1 to 50 do begin
{ Write to window at random locations }
Canvas.TextOut(Random(Width), Random(Height), 'Boo!');
end;
end;
procedure Randomize;
...
Randomize initializes the built-in random number generator with a random value (obtained from the system clock). The random number generator should be initialized by making a call to Randomize, or by assigning a value to RandSeed.
دقت کنید که خروجی روالهای فوق چندان هم Random نیست . برای کاربردهای حساس محاسباتی از این توابع استفاده نکنید اما برای کاربردهای عمومی مشکلی ایجاد نمیشه .
قبل از استفاده از تابع random از تابع randomize استفاده کن!! ولی به قول دوستمون این اعداد random واقعی نیستند و ممکنه که تکرار شند!!
سلام
پس چطوری رندم واقعی بسازم؟