Skip to content

Main content

Random Hexadecimal Value Generator Source Code

Browse the implementation files for Random Hexadecimal Value Generator.
@tool.io/tools/random/number source ↗
tool.ts typescript
import type { RandomSource } from '@tool.io/tools/random/number';
import { randomRadixValue } from '../radix-value/tool';

export const randomHexadecimal = (
	minimum: unknown,
	maximum: unknown,
	width: unknown,
	prefix: unknown,
	random: RandomSource = Math.random
): string =>
	randomRadixValue(minimum, maximum, width, prefix, 16, random);

export const Tool: TypeTool = {
	name: 'Random Hexadecimal Value Generator',
	slug: 'random/hexadecimal',
	intro:
		'Generate a random nonnegative integer formatted in base 16.',
	tool: randomHexadecimal,
	i: [
		{
			example: '0',
			label: 'Minimum',
			placeholder: 'Minimum integer',
			type: 'number',
			value: '0'
		},
		{
			example: '65535',
			label: 'Maximum',
			placeholder: 'Maximum integer',
			type: 'number',
			value: '65535'
		},
		{
			example: '4',
			label: 'Minimum width',
			placeholder: 'Hexadecimal digits',
			type: 'number',
			value: '4'
		},
		{
			example: 'include',
			label: 'Prefix',
			placeholder: 'Prefix',
			type: 'select',
			value: 'include',
			options: [
				{
					value: 'include',
					text: 'Include 0x',
					selected: true
				},
				{ value: 'none', text: 'No prefix' }
			]
		}
	],
	o: [
		{
			example: '0x7F2A',
			label: 'Random hexadecimal value',
			placeholder: 'Random hexadecimal value',
			render: 'textarea',
			type: 'text'
		}
	],
	rerunnable: true,
	alternative: [
		{ title: 'Random Binary Value', url: '/random/binary' },
		{ title: 'Random Octal Value', url: '/random/octal' },
		{ title: 'Random Hex Color', url: '/random/hex-color' }
	],
	cite: [
		{
			title: 'Hexadecimal - Wikipedia',
			url: 'https://en.wikipedia.org/wiki/Hexadecimal'
		}
	]
};

export default Tool;

Description

Browse the implementation files for Random Hexadecimal Value Generator.

References

  1. Tool.io on GitHub
  2. Tool.io TypeScript tools library

Similar or alternative tools