@@ -75,7 +75,7 @@ TypeScript) and add the following code to it:
75
75
``` ts
76
76
/* dice.ts*/
77
77
function rollOnce(min : number , max : number ) {
78
- return Math .floor (Math .random () * (max - min ) + min );
78
+ return Math .floor (Math .random () * (max - min + 1 ) + min );
79
79
}
80
80
81
81
export function rollTheDice(rolls : number , min : number , max : number ) {
@@ -92,7 +92,7 @@ export function rollTheDice(rolls: number, min: number, max: number) {
92
92
``` js
93
93
/* dice.js*/
94
94
function rollOnce (min , max ) {
95
- return Math .floor (Math .random () * (max - min) + min);
95
+ return Math .floor (Math .random () * (max - min + 1 ) + min);
96
96
}
97
97
98
98
function rollTheDice (rolls , min , max ) {
@@ -558,7 +558,7 @@ import { trace } from '@opentelemetry/api';
558
558
const tracer = trace .getTracer (' dice-lib' );
559
559
560
560
function rollOnce(min : number , max : number ) {
561
- return Math .floor (Math .random () * (max - min ) + min );
561
+ return Math .floor (Math .random () * (max - min + 1 ) + min );
562
562
}
563
563
564
564
export function rollTheDice(rolls : number , min : number , max : number ) {
@@ -579,7 +579,7 @@ const { trace } = require('@opentelemetry/api');
579
579
const tracer = trace .getTracer (' dice-lib' );
580
580
581
581
function rollOnce (min , max ) {
582
- return Math .floor (Math .random () * (max - min) + min);
582
+ return Math .floor (Math .random () * (max - min + 1 ) + min);
583
583
}
584
584
585
585
function rollTheDice (rolls , min , max ) {
@@ -707,7 +707,7 @@ nested operation. The following sample creates a nested span that tracks
707
707
``` ts
708
708
function rollOnce(i : number , min : number , max : number ) {
709
709
return tracer .startActiveSpan (` rollOnce:${i } ` , (span : Span ) => {
710
- const result = Math .floor (Math .random () * (max - min ) + min );
710
+ const result = Math .floor (Math .random () * (max - min + 1 ) + min );
711
711
span .end ();
712
712
return result ;
713
713
});
@@ -732,7 +732,7 @@ export function rollTheDice(rolls: number, min: number, max: number) {
732
732
``` js
733
733
function rollOnce (i , min , max ) {
734
734
return tracer .startActiveSpan (` rollOnce:${ i} ` , (span ) => {
735
- const result = Math .floor (Math .random () * (max - min) + min);
735
+ const result = Math .floor (Math .random () * (max - min + 1 ) + min);
736
736
span .end ();
737
737
return result;
738
738
});
@@ -849,7 +849,7 @@ information about the current operation that it's tracking.
849
849
``` ts
850
850
function rollOnce(i : number , min : number , max : number ) {
851
851
return tracer .startActiveSpan (` rollOnce:${i } ` , (span : Span ) => {
852
- const result = Math .floor (Math .random () * (max - min ) + min );
852
+ const result = Math .floor (Math .random () * (max - min + 1 ) + min );
853
853
854
854
// Add an attribute to the span
855
855
span .setAttribute (' dicelib.rolled' , result .toString ());
@@ -865,7 +865,7 @@ function rollOnce(i: number, min: number, max: number) {
865
865
``` js
866
866
function rollOnce (i , min , max ) {
867
867
return tracer .startActiveSpan (` rollOnce:${ i} ` , (span ) => {
868
- const result = Math .floor (Math .random () * (max - min) + min);
868
+ const result = Math .floor (Math .random () * (max - min + 1 ) + min);
869
869
870
870
// Add an attribute to the span
871
871
span .setAttribute (' dicelib.rolled' , result .toString ());
@@ -1466,7 +1466,7 @@ const tracer = trace.getTracer('dice-lib');
1466
1466
const meter = metrics .getMeter (' dice-lib' );
1467
1467
1468
1468
function rollOnce(min : number , max : number ) {
1469
- return Math .floor (Math .random () * (max - min ) + min );
1469
+ return Math .floor (Math .random () * (max - min + 1 ) + min );
1470
1470
}
1471
1471
1472
1472
export function rollTheDice(rolls : number , min : number , max : number ) {
@@ -1488,7 +1488,7 @@ const tracer = trace.getTracer('dice-lib');
1488
1488
const meter = metrics .getMeter (' dice-lib' );
1489
1489
1490
1490
function rollOnce (min , max ) {
1491
- return Math .floor (Math .random () * (max - min) + min);
1491
+ return Math .floor (Math .random () * (max - min + 1 ) + min);
1492
1492
}
1493
1493
1494
1494
function rollTheDice (rolls , min , max ) {
@@ -1523,7 +1523,7 @@ const counter = meter.createCounter('dice-lib.rolls.counter');
1523
1523
1524
1524
function rollOnce(min : number , max : number ) {
1525
1525
counter .add (1 );
1526
- return Math .floor (Math .random () * (max - min ) + min );
1526
+ return Math .floor (Math .random () * (max - min + 1 ) + min );
1527
1527
}
1528
1528
```
1529
1529
@@ -1535,7 +1535,7 @@ const counter = meter.createCounter('dice-lib.rolls.counter');
1535
1535
1536
1536
function rollOnce (min , max ) {
1537
1537
counter .add (1 );
1538
- return Math .floor (Math .random () * (max - min) + min);
1538
+ return Math .floor (Math .random () * (max - min + 1 ) + min);
1539
1539
}
1540
1540
```
1541
1541
0 commit comments