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 jbehring · Jan 18, 2017 at 09:28 PM · randomspawning

Weighted Random Spawning

I am working on a word game that I have made a bunch of letter prefabs for. Each prefab has a public float frequency variable. Where the "A" prefab frequency is 8.167 and the "Z" frequency is .074. How would I build a spawner that would instantiate prefabs randomly, but do so in such a way that A is more likely than Z based on the frequency variable?

Thanks,

Jason

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 jmgek · Jan 18, 2017 at 11:09 PM 1
Share

http://wiki.unity3d.com/index.php/WeightedRandomizer First page that showed up from typing "Weighted random spawning"

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by doublemax · Jan 18, 2017 at 09:30 PM

Add the two values together. Create a random number between 0 and the sum. If it's in the range [0-A], choose A, if it's in range [A - A+Z], choose Z.

Comment
Add comment · Show 3 · 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 juicyz · Jan 18, 2017 at 10:53 PM 0
Share

Assu$$anonymous$$g that A, B, C, .., Z that each frequency gets smaller and smaller. Wouldn't it be choose A if the random number is between 0 and A, choose B if the random number is between A and A + B, choose C if the random number is between A + B and A + B + C, ..., and choose Z if the random number is between A + B + C + .. + Y and A + B + C + ... + Y + Z ??

avatar image doublemax juicyz · Jan 19, 2017 at 12:06 AM 0
Share

What i wrote was for the case that you only have 2 values, A and Z. I didn't realize you meant a range of A-Z. Your interpretation is correct though.

avatar image juicyz doublemax · Jan 19, 2017 at 12:13 AM 0
Share

I thought so, just wanted to clarify for OP :)

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

7 People are following this question.

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

Related Questions

Spawning random questions at a time 1 Answer

Transform.position without Vector3? 1 Answer

Spawn help, 4 spawners but need one object on screen at a time 1 Answer

Spawning objects at 3 spawn points randomly one at a time. 1 Answer

Object Spawning Randomly 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