• 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 Destroypattern · Nov 21, 2016 at 09:35 PM · androidiosrandomhardwarenumbers

Random.seed on different hardware?

Does anyone know if t$$anonymous$$s method will present the same random numbers across different devices? Say both iOS and Android?

https://docs.unity3d.com/530/Documentation/ScriptReference/Random-seed.html

I know that seeds generate pseudo-random repeatable numbers. But I need it to do that across different specs of hardware. In most cases, the processor difference will present different sets of numbers for the same seed.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tanoshimi · Nov 21, 2016 at 09:59 PM

Given the same seed, Random.value will produce the same values in the same order whatever the target platform.

Comment
Add comment · Show 4 · 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 Bunny83 · Nov 22, 2016 at 02:15 AM 0
Share

I wouldn't say that with too much certainty ^^. Depending on the reliabiliby that is needed It's generally not recommended to use it for repeatable sequences as Unity could replace the PRNG in the future.

Some related posts:

https://blogs.unity3d.com/2015/01/07/a-primer-on-repeatable-random-numbers/

http://answers.unity3d.com/questions/393825/systemrandom-with-seed-not-matching-net-or-mono.html

As far as i remember Unity once switched to a different PRNG in the past. Also i thought i read somewhere that someone had already problems with different platforms, especially WindowsPhone since it uses MS .NET instead of Mono. Though, don't take my word on it, it's just something i remember (and human memory is known for it's flaws ^^).

ps: The simple PRNG i posted as answer to the linked question tend to form patterns on a larger scale, though on the other hand it's very simple. It highly depends on the usage. The Mersenne Twister has a hight quality of "randomness".

avatar image tanoshimi Bunny83 · Nov 22, 2016 at 07:18 AM 0
Share

I'm happy to be proved wrong but, to my knowledge, the implementation is deterministic and empirically I've always found that to be the case. Of course that implementation could change, so perhaps I should have qualified my answer with "given the same seed and version of Unity, Random.value will..." :)

avatar image Bunny83 tanoshimi · Nov 25, 2016 at 02:32 PM 0
Share

I finally found the old forum post i was searching for ages ^^:

https://forum.unity3d.com/threads/which-random-number-generator-does-unity-use.148601/

Sometimes google isn't really helpful ...

If you really want to ensure to always have the same implementation, just use your own. As Andeeeee said Unity uses (at least back then) Xorshift 128. It's really easy to implement. You could copy&paste 90% of the wikipedia sample code ^^.

edit
I quickly implemented the XorShift64: XorShift64.cs. I've implemented most common methods. If you miss something feel free to add it to your copy ^^. Or write some extension methods.

I tried to auto-initialize the seed in a way it's less "predictable". Most directly use DateTime.Ticks or Environment.TickCount. Though both have a bad resolution (that explains the problems most have when they create new Random instances in quick succession). "Stopwatch.GetTimestamp" is said to use a high performance counter if available, otherwise it does the same as DateTime.Ticks. So i just threw that in as well, doesn't hurt.

avatar image NoseKills · Nov 25, 2016 at 04:26 PM 0
Share

A bit off-topic, but I've understood that even normal float operations aren't necessarily deterministic in C# in general. So if total determinism is really required, some fixed point library is the way to go.

Though I've been wondering how this works in terms of the bigger picture since the actual running code is not C# for example on an iOS device...

Any insight would be appreciated.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

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

Empty game objects - too much? 3 Answers

Unity3d Social Logout 1 Answer

Update/Refresh screen before IAP InitiatePurchase 0 Answers

Mobile Computer Vision functionality advice 0 Answers

Detect Device Orientation Event 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