VB / VB.Net / VBS / VBA :
Dim Acak as Integer
Dim Awal as Integer = 1
Dim Akhir as Integer = 10
Randomize()
Acak = CInt( Int( ( Akhir - Awal + 1 ) * Rnd() + Awal ) )
C++ :
#include #include #include using namespace std; int main() { srand((unsigned)time(0)); int acak; acak = (rand()%akhir)+awal; }
Java (updated) :
import java.util.Random;
public final class AcakAcak {
public static void main(String... aArgs){
int awal = 1, akhir = 10, hasil;
Random acak = new Random();
for (int i=1; i<=5; i++){
hasil = (int)((akhir - awal + 1) * acak.nextDouble() + awal);
System.out.println(hasil);
}
}
}
JavaScript :
var awal = 1;
var akhir = 10;
var acak = Math.floor( ( akhir - ( awa - 1 ) ) * Math.random() ) + awal;
PHP :
$awal = 1;
$akhir = 10;
srand(time());
$random = ( rand() % $akhir ) + $awal;
1 komentar:
kita juga punya nih artikel mengenai 'Bilangan Acak', silahkan dikunjungi dan dibaca , berikut linknya
http://repository.gunadarma.ac.id/bitstream/123456789/1277/1/50407705.pdf
trimakasih
semoga bermanfaat
Posting Komentar