forked from BlueDome77/Turbowarp-Extension-List
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Simple Random Numbers.js
54 lines (51 loc) · 1.59 KB
/
Simple Random Numbers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class RandomNumber {
getInfo() {
return {
id: 'randomnumber',
name: 'Random Number',
blocks: [
{
opcode: 'randomInteger',
blockType: 'reporter',
text: 'pick random integer from [min] to [max]',
arguments: {
min: {
type: 'number',
defaultValue: 1
},
max: {
type: 'number',
defaultValue: 10
}
}
},
{
opcode: 'randomDecimal',
blockType: 'reporter',
text: 'pick random decimal from [min] to [max]',
arguments: {
min: {
type: 'number',
defaultValue: 0
},
max: {
type: 'number',
defaultValue: 1
}
}
}
]
};
}
randomInteger(args) {
const min = Math.floor(args.min);
const max = Math.floor(args.max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
randomDecimal(args) {
const min = args.min;
const max = args.max;
return Math.random() * (max - min) + min;
}
}
Scratch.extensions.register(new RandomNumber());