Announcement

Collapse
No announcement yet.

How would i go about making a random string?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How would i go about making a random string?

    EDIT: I think a random Char would be more useful

    We have random floats and integers but how would i generate a random string (basically a jumbled word from random) and of a certain length.

    Any advice would be appreciated.
    Last edited by Divinitize; 07-10-2014, 09:48 AM.

    #2
    You'd probably be better off doing this in C++, but what it boils down to is:

    You have an array of 26 characters (a-z), and you iterate through your word-length and append a character from the array by picking a random number between 0-25.

    Here's a working blueprint:
    Click image for larger version

Name:	randString.PNG
Views:	1
Size:	182.0 KB
ID:	1052516

    In case it isn't obvious, the high index in the ForLoop is your letter count. Just bear in mind your max index will be wordlength-1

    For a 6 character string:
    Code:
    LogBlueprintUserMessages: Generating...
    LogBlueprintUserMessages: mwldqz
    Code:
    LogBlueprintUserMessages: Generating...
    LogBlueprintUserMessages: ffbhpt
    Code:
    LogBlueprintUserMessages: Generating...
    LogBlueprintUserMessages: ndicrc
    Last edited by scrcr0; 07-10-2014, 10:11 AM.

    Comment


      #3
      Thanks for all your help, this was all to create a randomized registration plate for my vehicle on begin play, here is what i ended up with,

      I wanted the length to be 5 so i entered 0-4 on the loop as it's zero indexed.

      Comment


        #4
        Yeah that seems pretty solid. Just one thing I'd change in the interests of possible optimisation, would be to move the Set Text to fire off the 'completed' pin on the loop, so that you're not updating it each time you iterate through your loop.

        Comment


          #5
          Thanks for the advice

          Comment

          Working...
          X