@@ -13,9 +13,9 @@ import type { FeatureFlagScopeValue } from '../remote-feature-flag-controller-ty
1313 * - Hex format with 0x prefix (extension or old mobile implementation)
1414 *
1515 * For UUIDv4 format, the following normalizations are applied:
16- * - Replaces version (4) bits with 'f' to normalize range
17- * - Replaces variant bits (8-b) with 'f' to normalize range
1816 * - Removes all dashes from the UUID
17+ * - Remove version (4) bits and replace with 'f'
18+ * - Converts the remaining hex string to a BigInt for calculation
1919 *
2020 * For hex format:
2121 * - Expects a hex string with '0x' prefix (e.g., '0x1234abcd')
@@ -28,19 +28,18 @@ import type { FeatureFlagScopeValue } from '../remote-feature-flag-controller-ty
2828export function generateDeterministicRandomNumber (
2929 metaMetricsId : string ,
3030) : number {
31- let cleanId : string , value : bigint ;
31+ let cleanId : string ;
3232 // uuidv4 format
3333 if ( uuidValidate ( metaMetricsId ) && uuidVersion ( metaMetricsId ) === 4 ) {
34- cleanId = metaMetricsId . replace ( / ^ ( .{ 12 } ) 4 / u, '$1f' ) . replace ( / - / gu, '' ) ;
35- value = BigInt ( `0x${ cleanId } ` ) ;
34+ cleanId = metaMetricsId . replace ( / - / gu, '' ) . replace ( / ^ ( .{ 12 } ) 4 / u, '$1f' ) ;
3635 } else {
3736 // hex format with 0x prefix
3837 cleanId = metaMetricsId . slice ( 2 ) ;
39- value = BigInt ( `0x${ cleanId } ` ) ;
4038 }
39+ const value = BigInt ( `0x${ cleanId } ` ) ;
4140 const maxValue = BigInt ( `0x${ 'f' . repeat ( cleanId . length ) } ` ) ;
4241 // Use BigInt division first, then convert to number to maintain precision
43- return Number ( ( value * BigInt ( 1000000 ) ) / maxValue ) / 1000000 ;
42+ return Number ( ( value * BigInt ( 1_000_000 ) ) / maxValue ) / 1_000_000 ;
4443}
4544
4645/**
0 commit comments