@@ -75,7 +75,7 @@ TypeScript) and add the following code to it:
7575``` ts
7676/* dice.ts*/
7777function rollOnce(min : number , max : number ) {
78- return Math .floor (Math .random () * (max - min ) + min );
78+ return Math .floor (Math .random () * (max - min + 1 ) + min );
7979}
8080
8181export function rollTheDice(rolls : number , min : number , max : number ) {
@@ -92,7 +92,7 @@ export function rollTheDice(rolls: number, min: number, max: number) {
9292``` js
9393/* dice.js*/
9494function rollOnce (min , max ) {
95- return Math .floor (Math .random () * (max - min) + min);
95+ return Math .floor (Math .random () * (max - min + 1 ) + min);
9696}
9797
9898function rollTheDice (rolls , min , max ) {
@@ -558,7 +558,7 @@ import { trace } from '@opentelemetry/api';
558558const tracer = trace .getTracer (' dice-lib' );
559559
560560function rollOnce(min : number , max : number ) {
561- return Math .floor (Math .random () * (max - min ) + min );
561+ return Math .floor (Math .random () * (max - min + 1 ) + min );
562562}
563563
564564export function rollTheDice(rolls : number , min : number , max : number ) {
@@ -579,7 +579,7 @@ const { trace } = require('@opentelemetry/api');
579579const tracer = trace .getTracer (' dice-lib' );
580580
581581function rollOnce (min , max ) {
582- return Math .floor (Math .random () * (max - min) + min);
582+ return Math .floor (Math .random () * (max - min + 1 ) + min);
583583}
584584
585585function rollTheDice (rolls , min , max ) {
@@ -707,7 +707,7 @@ nested operation. The following sample creates a nested span that tracks
707707``` ts
708708function rollOnce(i : number , min : number , max : number ) {
709709 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 );
711711 span .end ();
712712 return result ;
713713 });
@@ -732,7 +732,7 @@ export function rollTheDice(rolls: number, min: number, max: number) {
732732``` js
733733function rollOnce (i , min , max ) {
734734 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);
736736 span .end ();
737737 return result;
738738 });
@@ -849,7 +849,7 @@ information about the current operation that it's tracking.
849849``` ts
850850function rollOnce(i : number , min : number , max : number ) {
851851 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 );
853853
854854 // Add an attribute to the span
855855 span .setAttribute (' dicelib.rolled' , result .toString ());
@@ -865,7 +865,7 @@ function rollOnce(i: number, min: number, max: number) {
865865``` js
866866function rollOnce (i , min , max ) {
867867 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);
869869
870870 // Add an attribute to the span
871871 span .setAttribute (' dicelib.rolled' , result .toString ());
@@ -1466,7 +1466,7 @@ const tracer = trace.getTracer('dice-lib');
14661466const meter = metrics .getMeter (' dice-lib' );
14671467
14681468function rollOnce(min : number , max : number ) {
1469- return Math .floor (Math .random () * (max - min ) + min );
1469+ return Math .floor (Math .random () * (max - min + 1 ) + min );
14701470}
14711471
14721472export function rollTheDice(rolls : number , min : number , max : number ) {
@@ -1488,7 +1488,7 @@ const tracer = trace.getTracer('dice-lib');
14881488const meter = metrics .getMeter (' dice-lib' );
14891489
14901490function rollOnce (min , max ) {
1491- return Math .floor (Math .random () * (max - min) + min);
1491+ return Math .floor (Math .random () * (max - min + 1 ) + min);
14921492}
14931493
14941494function rollTheDice (rolls , min , max ) {
@@ -1523,7 +1523,7 @@ const counter = meter.createCounter('dice-lib.rolls.counter');
15231523
15241524function rollOnce(min : number , max : number ) {
15251525 counter .add (1 );
1526- return Math .floor (Math .random () * (max - min ) + min );
1526+ return Math .floor (Math .random () * (max - min + 1 ) + min );
15271527}
15281528```
15291529
@@ -1535,7 +1535,7 @@ const counter = meter.createCounter('dice-lib.rolls.counter');
15351535
15361536function rollOnce (min , max ) {
15371537 counter .add (1 );
1538- return Math .floor (Math .random () * (max - min) + min);
1538+ return Math .floor (Math .random () * (max - min + 1 ) + min);
15391539}
15401540```
15411541
0 commit comments