A PHP Error was encountered

Severity: 8192

Message: Return type of CI_Session_files_driver::open($save_path, $name) should either be compatible with SessionHandlerInterface::open(string $path, string $name): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Filename: drivers/Session_files_driver.php

Line Number: 113

A PHP Error was encountered

Severity: 8192

Message: Return type of CI_Session_files_driver::close() should either be compatible with SessionHandlerInterface::close(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Filename: drivers/Session_files_driver.php

Line Number: 280

A PHP Error was encountered

Severity: 8192

Message: Return type of CI_Session_files_driver::read($session_id) should either be compatible with SessionHandlerInterface::read(string $id): string|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Filename: drivers/Session_files_driver.php

Line Number: 145

A PHP Error was encountered

Severity: 8192

Message: Return type of CI_Session_files_driver::write($session_id, $session_data) should either be compatible with SessionHandlerInterface::write(string $id, string $data): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Filename: drivers/Session_files_driver.php

Line Number: 223

A PHP Error was encountered

Severity: 8192

Message: Return type of CI_Session_files_driver::destroy($session_id) should either be compatible with SessionHandlerInterface::destroy(string $id): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Filename: drivers/Session_files_driver.php

Line Number: 303

A PHP Error was encountered

Severity: 8192

Message: Return type of CI_Session_files_driver::gc($maxlifetime) should either be compatible with SessionHandlerInterface::gc(int $max_lifetime): int|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Filename: drivers/Session_files_driver.php

Line Number: 344

A PHP Error was encountered

Severity: 8192

Message: setcookie(): Passing null to parameter #7 ($httponly) of type bool is deprecated

Filename: core/Input.php

Line Number: 410

rand() Fonksiyonu ile Rastgele Sayı Üretmek
Öneri ve Hata Raporu



Günün Sözü Sevemez kimse seni benim sevdiğim kadar

kategori PHP
oylama 3/5 yorum 1 yorum yazar Hakan Taşan tarih 30 Ekim 2013

rand() fonksiyonunu rastgele bir sayı üretmek istediğimizde kullanırız. İsterseniz parametresiz kullanabilirsiniz, isterseniz de 2 parametre vererek sayının bu minimum ve maksimum değerler arasında üretilmesini sağlayabilirsiniz. rand() fonksiyonunun parametresiz kullanımında üretilecek maksimum sayı değeri bazı işletim sistemlerinde (Windows) 32767 olarak tanımlıdır. Bu sayıdan daha yüksek sayılar üretmek istiyorsanız rand() fonksiyonundan 4 kat daha hızlı olan mt_rand() fonksiyonunu kullanmanızı tavsiye ediyorum.

Syntax

rand();
rand(min,max);

 

min: Üretilecek sayının alabileceği minimum değer. Varsayılan değer 0.

max: Üretilecek sayının alabileceği maksimum değer. Varsayılan değer getrandmax() fonksiyonu ile öğrenilir. Bazı işletim sistemlerinde bu değer farklılık gösterir.

Not: getrandmax() fonksiyonu rand() fonksiyonu ile üretilebilecek maksimum sayı değerini gösterir.

Örnek Kod

<?php
    echo rand(); // 0 ile getrandmax() arasında bir sayı: 23657
    echo rand(20,50); // 20 ile 50 arasında bir sayı: 21
    echo rand(-10,20); // -10 ile 20 arasında bir sayı: -1
    echo getrandmax(); // getrandmax() ile üretilebilecek maksimum sayı değeri: 32767
?>

 

paylaş Paylaş
oylama yap Oyla

makale yorumları YORUMLAR

1 Yorum


yorum

Arif Cemre

11 Nisan 2017 00:00


Teşekkürler