Tạo ngẫu nhiên 2 số có cùng hàng chục
Mã nguồn mô phỏng bằng javascript
var AXxAY = function () { this.onCreateNumber = function () { n0 = Core.random(10); while (n0 == 0) n0 = Core.random(10); n1 = Core.random(10); while (n1 == 0) n1 = Core.random(10); n2 = Core.random(10); while (n2 == 0 || n2 == n1) n2 = Core.random(10); this.number1 = n0 * 10 + n1; this.number2 = n0 * 10 + n2; number1PlusN2 = this.number1 + n2; lengthNumber1PlusN2 = (number1PlusN2 + "").length; n0_x_number1PlusN2 = n0 * number1PlusN2; lengthN0_x_number1PlusN2 = (n0_x_number1PlusN2 + "").length; n11_x_n22 = n1 * n2; lengthN11_x_n22 = (n11_x_n22 + "").length; if (n11_x_n22 > 9) { t1 = parseInt((n11_x_n22 + "").charAt(0)); n0_x_number1PlusN2_t1 = n0_x_number1PlusN2 + t1; lengthN0_x_number1PlusN2_t1 = (n0_x_number1PlusN2_t1 + "").length; t2 = parseInt((n11_x_n22 + "").charAt(1)); } } this.onCreateScripts = function (scripts) { // Lấy ra number1 + với n2 scripts.push(this.createScript0()); // Hiển thị number1 + với n2 scripts.push(this.createScript01()); scripts.push(this.createScript0_1()); // Hiển thị number1 + với n2 // Thực hiện cộng number1 với n2 scripts.push(this.createScript1(number1PlusN2)); // Hiển thị kết quả number1 + n2 // Hiển thị phép tính nhân số n0 * với number1PlusN22 scripts.push(this.createScript2()) scripts.push(this.createScript21(number1PlusN2)) scripts.push(this.createScript2_1()); // Lấy ra n0 * với number1PlusN2 scripts.push(this.createScript3(n0_x_number1PlusN2)); // Hiển thị kết quả số thứ 1 của number1 * với number1PlusN22 scripts.push(this.createScript3_1(n0_x_number1PlusN2)); // Hiển thị một phần kết quả scripts.push(this.createScript4()); // Hiển thị phép tính nhân n1 * n2 scripts.push(this.createScript41()); scripts.push(this.createScript4_1()); scripts.push(this.createScript5(n11_x_n22)); // Hiển thị kết quả n11_x_n22 = n11 * n22; if (n11_x_n22 <= 9) scripts.push(this.createScript6(n0_x_number1PlusN2, n11_x_n22)); // Hiển thị kết quả cuối cùng else { scripts.push(this.createScript7()); scripts.push(this.createScript71(n0_x_number1PlusN2)) scripts.push(this.createScript7_1(t1)); scripts.push(this.createScript8(n0_x_number1PlusN2_t1)); // Hiển thị kết quả gần cuối cùng scripts.push(this.createScript9(n0_x_number1PlusN2_t1)); scripts.push(this.createScript10(n0_x_number1PlusN2_t1, t2)); } }; } var pageMathX = new PageMathX(); pageMathX.mathX = new AXxAY(); pageMathX.start();
Các bạn có thể xem chi tiết nội dung mã nguồn tại đây
Sơn 20