提交 ac509b12 编写于 作者: J Jason Park

add Integer.random function

上级 54d27909
'use strict';
const Integer = require('./integer');
const random = (N, M, min, max) => {
if (!N) N = 10;
if (!M) M = 10;
......@@ -9,7 +11,7 @@ const random = (N, M, min, max) => {
for (var i = 0; i < N; i++) {
D.push([]);
for (var j = 0; j < M; j++) {
D[i].push((Math.random() * (max - min + 1) | 0) + min);
D[i].push(Integer.random(min, max));
}
}
return D;
......
'use strict';
const Integer = require('./integer');
const random = (N, min, max) => {
if (!N) N = 7;
if (!min) min = 1;
......@@ -8,7 +10,7 @@ const random = (N, min, max) => {
for (var i = 0; i < N; i++) C[i] = new Array(2);
for (var i = 0; i < N; i++)
for (var j = 0; j < C[i].length; j++)
C[i][j] = (Math.random() * (max - min + 1) | 0) + min;
C[i][j] = Integer.random(min, max);
return C;
};
......
'use strict';
const Integer = require('./integer');
const Array1D = require('./array1d');
const Array2D = require('./array2d');
const CoordinateSystem = require('./coordinate_system');
......@@ -9,6 +10,7 @@ const WeightedDirectedGraph = require('./weighted_directed_graph');
const WeightedUndirectedGraph = require('./weighted_undirected_graph');
module.exports = {
Integer,
Array1D,
Array2D,
CoordinateSystem,
......
'use strict';
const random = (min, max) => {
return (Math.random() * (max - min + 1) | 0) + min;
};
module.exports = {
random
};
'use strict';
const Integer = require('./integer');
const random = (N, ratio, min, max) => {
if (!N) N = 5;
if (!ratio) ratio = .3;
......@@ -10,7 +12,7 @@ const random = (N, ratio, min, max) => {
G[i] = new Array(N);
for (var j = 0; j < N; j++) {
if (i != j && (Math.random() * (1 / ratio) | 0) == 0) {
G[i][j] = (Math.random() * (max - min + 1) | 0) + min;
G[i][j] = Integer.random(min, max);
}
}
}
......
'use strict';
const Integer = require('./integer');
const random = (N, ratio, min, max) => {
if (!N) N = 5;
if (!ratio) ratio = .3;
......@@ -10,7 +12,7 @@ const random = (N, ratio, min, max) => {
for (var i = 0; i < N; i++) {
for (var j = 0; j < N; j++) {
if (i > j && (Math.random() * (1 / ratio) | 0) == 0) {
G[i][j] = G[j][i] = (Math.random() * (max - min + 1) | 0) + min;
G[i][j] = G[j][i] = Integer.random(min, max);
}
}
}
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册