Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by TheShadyColombian · May 13, 2015 at 02:34 AM · c#randomstring

Generate a random string from a specified length.

Could someone help me make a code snippet (in C#) that can generate a random string (and assign it to a variable, which should be easy) from a specified length from an "int" variable (which will be slightly randomized) for a game item that is supposed to be glitchy. It'd be great if it could be done so it also generates special characters (î, ä, é, ç, ø, ¡, å, †, ®, ∂, ˙, ©, ¬, ˚, ˜, all of which I wrote by holding down option and a random letter, So I know it's basic ASCII)

Any help will be greatly appreciated!

  ~Juan Callejas
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Eric5h5 · May 13, 2015 at 03:47 AM 0
Share

None of those characters are basic ASCII, but Unity doesn't use ASCII anyway, it uses Unicode.

avatar image TheShadyColombian · May 13, 2015 at 04:19 AM 0
Share

Right. $$anonymous$$istook those. I don't know that much about it, but those extra chars are Unicode, right?

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by barbe63 · May 13, 2015 at 02:52 AM

Set a string to be the array of your authorized characters like this:

    const string glyphs= "abcdefghijklmnopqrstuvwxyz0123456789"; //add the characters you want

Then after declaring your string variable(here myString), do this:

 int charAmount = Random.Range(minCharAmount, maxCharAmount); //set those to the minimum and maximum length of your string
 for(int i=0; i<charAmount; i++)
 {
     myString += glyphs[Random.Range(0, glyphs.Length)];
 }
Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fafase · May 13, 2015 at 04:10 AM 1
Share

If the string is long, StringBuilder would be better.

avatar image barbe63 · May 13, 2015 at 04:15 AM 1
Share

Indeed, or garbage colector would have a lot of job.

avatar image TheShadyColombian · May 13, 2015 at 04:20 AM 0
Share

Will this make it flicker or make it noticeable that it's changing? Because I plan on having it flicker random strings constantly

avatar image barbe63 · May 13, 2015 at 04:37 AM 0
Share

Interesting study about the 3 methods : http://fr.slideshare.net/sindharta/c-string-concatenations-in-unity I don't understand your last question.

avatar image xortrox · May 13, 2015 at 10:56 AM 0
Share

I'm guessing by flickering you mean you want the string to randomize regularly during the gameplay to simulate some data "error" or an obscured text. To do that you would have to call this function barbe63 provided at an interval. I would suggest this for that.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make a list with unique strings randomly 1 Answer

Distribute terrain in zones 3 Answers

Random role assigning from string array 1 Answer

(c#) display a random string at game over 2 Answers

Multiple Cars not working 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges