Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
avatar image
0
Question by Shnayzr · Jan 05, 2016 at 12:51 AM · randomrandom.rangerandomize

is there a way to make Random.Range be more Random?

Hello

i found that when i debug Random.Range from 1 to 500 in Update(), all values appear the same number of times.

is there a way to make the values more random or better random function?

i hope you understood my question.

Comment
Add comment · Show 4
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 $$anonymous$$ · Jan 05, 2016 at 01:00 AM 0
Share

Can you post your code here? I tried out this and everything worked fine void Update () { Debug.Log(Random.Range(0, 500)); }

Also, do you mean that every number logged to console is the same?

avatar image Shnayzr $$anonymous$$ · Jan 05, 2016 at 01:09 AM 0
Share

yea same code but i used 50 in this example to save time waiting. check this image, almost all of them fall in the range of 80~90, i dont see any of them for example, 20 times while another one is 100 or something like that alt text

randomrange.png (58.9 kB)
avatar image maccabbe Shnayzr · Jan 05, 2016 at 01:19 AM 1
Share

That's exactly the behaviour you would expect from randomly selecting 1-50. Perhaps it would help if you explained what results you expected or what you were using this for.

For instance, for damage I would suggest reducing randomness using a dice like system as explained http://www.redblobgames.com/articles/probability/damage-rolls.html.

Show more comments

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by flagDiZero · May 15, 2018 at 03:07 PM

Hi!

here it is (unity 5) or this (actual)

You can istantiate the seed (or the init) state every time that you need a random. Maybe with the delta time or something changing

Comment
Add comment · 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
0

Answer by Topthink · May 15, 2018 at 10:48 PM

Try this, it makes Random a bit more random. Good luck.

 Random.InitState ((int)System.DateTime.Now.Ticks); // Makes things more random
Comment
Add comment · 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
0

Answer by The_Icaruz · May 16, 2018 at 05:25 AM

So if I'm not wrong the values on the left of your screenshot are the random numbers you get and not the one on the right.

I see your numbers are between 1 and 50 like you set it up in your code.

If I misunderstood your question just let me know.

Comment
Add comment · 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

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

37 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 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

Random.Range is not changing? 1 Answer

Random.Range doesnt work anymore 4 Answers

How to randomize answers? 1 Answer

How to make Random.Range() step by a certain amount? 1 Answer

Randomize texture within prefab 0 Answers


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