Bookmark this: tool.io/random/binary/source-code
Random Binary Value Generator Source Code
Browse the implementation files for Random Binary Value Generator.tool.ts typescript
import type { RandomSource } from '@tool.io/tools/random/number';
import { randomRadixValue } from '../radix-value/tool';
export const randomBinary = (
minimum: unknown,
maximum: unknown,
width: unknown,
prefix: unknown,
random: RandomSource = Math.random
): string =>
randomRadixValue(minimum, maximum, width, prefix, 2, random);
export const Tool: TypeTool = {
name: 'Random Binary Value Generator',
slug: 'random/binary',
intro:
'Generate a random nonnegative integer formatted in base 2.',
tool: randomBinary,
i: [
{
example: '0',
label: 'Minimum',
placeholder: 'Minimum integer',
type: 'number',
value: '0'
},
{
example: '255',
label: 'Maximum',
placeholder: 'Maximum integer',
type: 'number',
value: '255'
},
{
example: '8',
label: 'Minimum width',
placeholder: 'Binary digits',
type: 'number',
value: '8'
},
{
example: 'include',
label: 'Prefix',
placeholder: 'Prefix',
type: 'select',
value: 'include',
options: [
{
value: 'include',
text: 'Include 0b',
selected: true
},
{ value: 'none', text: 'No prefix' }
]
}
],
o: [
{
example: '0b00101010',
label: 'Random binary value',
placeholder: 'Random binary value',
render: 'textarea',
type: 'text'
}
],
rerunnable: true,
alternative: [
{ title: 'Random Octal Value', url: '/random/octal' },
{
title: 'Random Hexadecimal Value',
url: '/random/hexadecimal'
},
{ title: 'Random Number', url: '/random/number' }
],
cite: [
{
title: 'Binary number - Wikipedia',
url: 'https://en.wikipedia.org/wiki/Binary_number'
}
]
};
export default Tool;
Description
Browse the implementation files for Random Binary Value Generator.