Revision history for RandomNumbers


Revision [128]

Last edited on 2018-12-09 02:19:38 by IanRastall

No Differences

Revision [127]

Edited on 2018-12-09 02:19:38 by IanRastall
Additions:
A class is named, and designated available in any scope. Inside it is the main() method, which contains a call to println().
This code would be saved as a .java file, and run in a console environment.


Revision [126]

Edited on 2018-12-09 02:16:25 by IanRastall

No Differences

Revision [125]

Edited on 2018-12-09 02:16:25 by IanRastall
Additions:
public class RandomNumber {
public static void main(String[] args) {
System.out.println((int) (Math.random() * 100));
Deletions:
import java.util.*;
public class generateRandom
public static void main(String args[])
System.out.println("Math.random());
}


Revision [124]

Edited on 2018-12-09 02:01:39 by IanRastall

No Differences

Revision [123]

Edited on 2018-12-09 02:01:39 by IanRastall
Additions:
import java.util.*;
public class generateRandom
public static void main(String args[])
System.out.println("Math.random());
}
Deletions:
public class RandomNumber{
public static void main(String[] args) {
System.out.println(Math.random());


Revision [122]

Edited on 2018-12-09 00:26:25 by IanRastall

No Differences

Revision [121]

Edited on 2018-12-09 00:26:25 by IanRastall
Additions:
Before the HTML is processed, the server processes the PHP. It does this because the .php file extension is used. The echo() function prints a random number between 1 and 100 in the body of the (blank) HTML document.


Revision [120]

Edited on 2018-12-09 00:22:33 by IanRastall

No Differences

Revision [119]

Edited on 2018-12-09 00:22:33 by IanRastall
Additions:
**In PHP**
%%(php)
<title>PHP Test</title>
<?php echo rand(1, 100); ?>


Revision [118]

Edited on 2018-12-09 00:18:53 by IanRastall

No Differences

Revision [117]

Edited on 2018-12-09 00:18:53 by IanRastall
Additions:
**In Python**
The code is saved as a text file with a .py extension, then run in a console environment.
%%(python)
import random
print random.randint(1,101)


Revision [116]

Edited on 2018-12-09 00:15:37 by IanRastall

No Differences

Revision [115]

Edited on 2018-12-09 00:15:37 by IanRastall
Additions:
**In Java**
%%(java)
public class RandomNumber{
public static void main(String[] args) {
System.out.println(Math.random());


Revision [110]

Edited on 2018-12-09 00:05:47 by IanRastall

No Differences

Revision [109]

Edited on 2018-12-09 00:05:47 by IanRastall
Additions:
**In ""JavaScript""**
The browser, running the ""JavaScript"", will run the randomNumber() method once the button is clicked. That method selects the element with the id ""jsTest"" (which is the <p>) and initializes a variable with its (empty) value. A random number between 1 and 100 is then assigned to its ""innerHTML"" property. This changes the content of that element.
%%(javascript)
<html>
<head>
<title>JavaScript Test</title>
</head>
<body>
<button onclick="randomNumber()">Go</button>
<p id="jsTest"></p>
<script>
function randomNumber() {
var x = document.getElementById("jsTest")
x.innerHTML = Math.floor((Math.random() * 100) + 1);
</script>
</body>
</html>


Revision [108]

Edited on 2018-12-08 23:53:43 by IanRastall

No Differences

Revision [107]

Edited on 2018-12-08 23:53:43 by IanRastall
Additions:
Two standard libraries are imported, and a namespace is established. Inside the main() method, an integer variable is given the value of a random number between 1 and 100. This is then sent to the standard output stream. A return value of 0 tells the program to exit.


Revision [106]

Edited on 2018-12-08 23:51:16 by IanRastall

No Differences

Revision [105]

Edited on 2018-12-08 23:51:16 by IanRastall
Additions:
**In C""++""**
%%(cpp)
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int r = (rand() % 100) + 1;
cout << r << " ";


Revision [104]

Edited on 2018-12-08 23:49:46 by IanRastall

No Differences

Revision [103]

Edited on 2018-12-08 23:49:46 by IanRastall
Additions:
Two standard libraries are imported. Inside the main() function the printf() function is run, calling the rand() function, which is given as the string to print. A return value of 0 tells the program to exit.


Revision [102]

Edited on 2018-12-08 23:48:15 by IanRastall

No Differences


Full history for this page cannot be displayed within a single page, click here to view more.

Valid XHTML :: Valid CSS: :: Powered by WikkaWiki