Jump to content

Random characters


Recommended Posts

I'm trying to create a bunch of random letters but i don't really know how to get it done.

My plan was to use a `trunc(fit(rand($ID),0,1,a,z))` with a and z being the ansi codes of the range of characters i want to use.

I do however not know how to turn a number into the corresponding character.

Another option would be to use a substring from a predifined string with all the characters i want to include but i don't know how to get a substring out of a variable neither.

Yet another way would be to make all characters as objects and just use a random number to select with object to merge but that's not a very ellegant way to do it i think.

Can anyone put me in the right direction?

Edited by Rudinie
Link to comment
Share on other sites

to get character based on something like ASCII number you can type \\`33` in the text parameter of the font sop

it will give you letter A which corresponds to code 33 (at least in houdini, i am not sure what table it is based on)

so you can create code range for your stamp variable

e.g :

variable char = round(fit01(rand($ID),65,90))

codes 65-90 correspond to lowercase a-z

and in your copied font sop put this in text field

\\`stamp("../copy1","char",65)`

there is also possibility to create character set and use random characters from this set

the set will be string parameter in space separated characters like: a b c x y z 1 2 3

and then you can use expressions like arg() and argc() to choose random character from this set and use for stamping

  • Like 1
Link to comment
Share on other sites

Wait, I remembered.

If you use the "\\" it will use ASCII code instead of what you write, so you have access to all characters.

The 33 thing that anin wrote above is because the first 31 non-printing characters are skipped, so you actualy have 93 instead of 127 characters.

If you write \\`int(fit01(rand($F),1,94))` at the Font SOP it will give you every possible character , or use 65-90 for lower case letters.

EDIT: anim beat me to it. He

Edited by Netvudu
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...