Tutorial by Examples: dom

DOM stands for Document Object Model. It is an object-oriented representation of structured documents like XML and HTML. Setting the textContent property of an Element is one way to output text on a web page. For example, consider the following HTML tag: <p id="paragraph"></p&g...
import random shuffle() You can use random.shuffle() to mix up/randomize the items in a mutable and indexable sequence. For example a list: laughs = ["Hi", "Ho", "He"] random.shuffle(laughs) # Shuffles in-place! Don't do: laughs = random.shuffle(laughs) p...
import random randint() Returns a random integer between x and y (inclusive): random.randint(x, y) For example getting a random number between 1 and 8: random.randint(1, 8) # Out: 8 randrange() random.randrange has the same syntax as range and unlike random.randint, the last value is no...
Setting a specific Seed will create a fixed random-number series: random.seed(5) # Create a fixed state print(random.randrange(0, 10)) # Get a random integer between 0 and 9 # Out: 9 print(random.randrange(0, 10)) # Out: 4 Resetting the seed will create the same &qu...
var a = Math.random(); Sample value of a: 0.21322848065742162 Math.random() returns a random number between 0 (inclusive) and 1 (exclusive) function getRandom() { return Math.random(); } To use Math.random() to get a number from an arbitrary range (not [0,1)) use this function to get a...
The function rand() can be used to generate a pseudo-random integer value between 0 and RAND_MAX (0 and RAND_MAX included). srand(int) is used to seed the pseudo-random number generator. Each time rand() is seeded wih the same seed, it must produce the same sequence of values. It should only be see...
The following is an example that displays 5 one-dimensional random walks of 200 steps: y = cumsum(rand(200,5) - 0.5); plot(y) legend('1', '2', '3', '4', '5') title('random walks') In the above code, y is a matrix of 5 columns, each of length 200. Since x is omitted, it defaults to the row n...
The jQuery function (usually aliased as $) can be used both to select elements and to create new elements. var myLink = $('<a href="http://stackexchange.com"></a>'); You can optionally pass a second argument with element attributes: var myLink = $('<a>', { 'href': 'h...
// Create an array with a fixed size and type. var array = new Uint8Array(5); // Generate cryptographically random values crypto.getRandomValues(array); // Print the array to the console console.log(array); crypto.getRandomValues(array) can be used with instances of the following classes...
arc4random_uniform(someNumber: UInt32) -> UInt32 This gives you random integers in the range 0 to someNumber - 1. The maximum value for UInt32 is 4,294,967,295 (that is, 2^32 - 1). Examples: Coin flip let flip = arc4random_uniform(2) // 0 or 1 Dice roll let roll = arc4random_...
Java provides, as part of the utils package, a basic pseudo-random number generator, appropriately named Random. This object can be used to generate a pseudo-random value as any of the built-in numerical datatypes (int, float, etc). You can also use it to generate a random Boolean value, or a random...
The method nextInt(int bound) of Random accepts an upper exclusive boundary, i.e. a number that the returned random value must be less than. However, only the nextInt method accepts a bound; nextLong, nextDouble etc. do not. Random random = new Random(); random.nextInt(1000); // 0 - 999 int num...
The Arbitrary class is for types that can be randomly generated by QuickCheck. The minimal implementation of Arbitrary is the arbitrary method, which runs in the Gen monad to produce a random value. Here is an instance of Arbitrary for the following datatype of non-empty lists. import Test.QuickC...
By default the Python random module use the Mersenne Twister PRNG to generate random numbers, which, although suitable in domains like simulations, fails to meet security requirements in more demanding environments. In order to create a cryptographically secure pseudorandom number, one can use Syst...
In order to create a random user password we can use the symbols provided in the string module. Specifically punctuation for punctuation symbols, ascii_letters for letters and digits for digits: from string import punctuation, ascii_letters, digits We can then combine all these symbols in a name...
Similarly to the SimpleXML, you can use DOMDocument to parse XML from a string or from a XML file 1. From a string $doc = new DOMDocument(); $doc->loadXML($string); 2. From a file $doc = new DOMDocument(); $doc->load('books.xml');// use the actual file path. Absolute or relative Exa...
Math.random(); produces an evenly distributed random number between 0 (inclusive) and 1 (exclusive) Example output: 0.22282187035307288 0.3948539895936847 0.9987191134132445
function randomMinMax(min:Number, max:Number):Number { return (min + (Math.random() * Math.abs(max - min))); } This function is called by passing a range of minimum and maximum values. Example: randomMinMax(1, 10); Example outputs: 1.661770915146917 2.5521070677787066 9.4362709657...
function randomAngle():Number { return (Math.random() * 360); } Example outputs: 31.554428357630968 230.4078639484942 312.7964010089636
To generate true random values that can be used for cryptography std::random_device has to be used as generator. #include <iostream> #include <random> int main() { std::random_device crypto_random_generator; std::uniform_int_distribution<int> int_distribution(0,9); ...

Page 1 of 7