Sign in to follow this  
Followers 0
mlloz

generator

8 posts in this topic

hello,

how can i create a hex string generator composed of 7 characters?

Share this post


Link to post
Share on other sites



Create a random number between your values, and then convert it to hex.

By default Hex numbers are 8 chars... just strip the leading 0 if your script doesn't handle it.

For $i=1 To 10
$hexnum = Random(Dec('1000000'),Dec('fffffff'),1)
ConsoleWrite(Hex($hexnum)&@CRLF)
Next

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Share this post


Link to post
Share on other sites

thank you :)

take a look to my previous code..

$q = Chr(Random(48 , 57)) & Chr(Random(65, 70))

$w = Chr(Random(48, 57)) & Chr(Random(65, 70))

$e = Chr(Random(48, 57)) & Chr(Random(65, 70))

$r = Chr(Random(48, 57)) & Chr(Random(65, 70))

$t = Chr(Random(48, 57)) & Chr(Random(65, 70))

$y = Chr(Random(48, 57)) & Chr(Random(65, 70))

$u = Chr(Random(48, 57)) & Chr(Random(65, 70))

$string = $q & $w & $e & $r & $t & $y & $u

Share this post


Link to post
Share on other sites

Well, everyone has to start somewhere. :)

I just need to convert from hex to dec and back fairly regularly so I'm very familiar with those functions.


Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Share this post


Link to post
Share on other sites

but its 7 characters this code generates 8 characters

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

While 1
    $String = ""
    For $i = 1 To 7
        $String &= StringRight(Hex(Random(0, 16,1)), 1)

    Next
    MsgBox(0, "Your Hex String", $String)
WEnd

Regards, Rudi.

[edit]

modified code, using Random() to return an integer directly.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

By default Hex numbers are 8 chars... just strip the leading 0 if your script doesn't handle it.

Yes they are. can can use stringtrimleft() if needed.


Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Share this post


Link to post
Share on other sites

thank you guys :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0