检查是否已随机选择字节 [英] Check if a random selection of bytes has already been generated

查看:90
本文介绍了检查是否已随机选择字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.

我写了一种生成随机MAC地址(6个字节)的方法.

首先,我创建一个唯一的GUID.

接下来,我将GUID转换为字节数组.

最后,我从GUID字节数组中的特定位置选择6个字节,并将其格式化为十六进制MAC地址字符串.

我想做的是(在我的字节数组函数中)检查是否已生成任何生成的MAC地址,并处理这种情况.

最好怎么做?

谢谢

我尝试过的事情:

尝试了一些似乎不起作用的比较函数

Hi.

I have wrote a method that generates random MAC addresses (6 bytes).

First, I create a unique GUID.

Next, I convert the GUID to a byte array.

Finally, I select 6 bytes from specific locations in the GUID byte array and format this as a HEX MAC address string.

What I would like to do is check (in my byte array function) if any of the generated MAC addresses have already been generated, and handle that situation.

How is best to do this?

Thank you

What I have tried:

Tried a number of compare functions that do notseem to work

推荐答案

它只有6个字节,因此您可以很容易地编写一个函数,只需检查一下是否生成的字符串已经在您先前生成的字节字符串的集合中.

就像从集合中获取字符串并编写for循环以比较字节一样简单.
It''s only 6 bytes, so you can write a function quite easily that just checks to see if the generated string is already in your collection of previously generated strings of bytes.

It''s as simple as getting a string from the collection and writing a for loop to compare the bytes.


这篇关于检查是否已随机选择字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆