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 ColinBurke · Jun 22, 2012 at 09:20 PM · c#randomprogrammingmathseed

How do I seed the random number generator myself and still get pseudorandom values?

How do I change the Random.seed myself relative to other variables to still get pseudorandom output?

Consider the following C# code:

    float RandomFromXAndY(int x, int y) {
         Random.seed = x * y; //Repeating, not pseudorandom.
         return Random.value;
     }

The problem is there are multiple combinations of x and y that can yield their same product (e.g., 3 6 or 6 3 both equal 18). So the result may yield the same, even when different combinations of x and y values are used. When generating x and y linearly, it becomes possible to mathematically predict the repetition.

How do I generate a random seed that is more "random", or pseudorandom from x and y?

Comment
Add comment · Show 1
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 MountDoomTeam · Jan 19, 2013 at 09:08 AM 0
Share

yes you could also use the square root of both numbers.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by whydoidoit · Jun 22, 2012 at 09:23 PM

You add them together and multiply both by different prime numbers.

Comment
Add comment · Show 5 · 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 Wolfram · Jun 22, 2012 at 10:51 PM 1
Share

This suggestion will effectively prevent visible repetition patterns/mirroring effects between x and y.

If you want to guarantee that there are no duplicate seeds whatsoever, at least one of your primes needs to be larger than your possible maximum value of x and y.

avatar image whydoidoit · Jun 22, 2012 at 11:05 PM 0
Share

@wolfram A damn good point.

avatar image Berenger · Jun 22, 2012 at 11:11 PM 0
Share

Isn't the seed updated each time you use Random.XXX ? Calling Random.value twice doesn't get you the same thing. That doesn't each result unique though, using prime numbers is the way to go.

avatar image Wolfram · Jun 22, 2012 at 11:18 PM 0
Share

Hm, I haven't tried with Unity, but I thought the idea of a seed was that consecutive calls to Random.value produce the same series of random numbers for the same seed?

avatar image whydoidoit · Jun 22, 2012 at 11:21 PM 0
Share

Yeah that's what happens when I do it - I choose a seed then it repeats the same sequence, each step being pseudorandom. If you want to always get a random number between 0 and 1 (or whatever) and you want to make sure it is the same number given a set of standard inputs - it looks like prime numbers are the way to go.

avatar image
0

Answer by ceptri · Apr 30, 2013 at 11:46 PM

You just need to be careful about trusting the random to be the same. If some other system calls random in the middle of this function, the same seed won't produce the same set of numbers since Random is global.

In reality, this system should be refactored so you make your own stream object, then you can control who is called it and insure that the stream of random number is always the same.

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

6 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Generate FTL style star map 0 Answers

Generate the same 'random' number sequence from a seed 1 Answer

Randomly place a specific number of objects? 1 Answer

Strange random seed issue with level generation 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