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 /
avatar image
0
Question by sdgd · Mar 15, 2013 at 04:55 AM · c#findfloatingpoint

any else way finding floating point

is there any else way finding only floating point?

 char c;
 float f = Time.time;
 f -= (int) f;
 if (f < 0.5){
     c = 'z';
 }
 else{
     c = 'x';
 }

I know I could do it with random but I don't want random

and if there is a way I'd like to know how to find let say everything that's after

0.00...

Comment
Add comment · Show 3
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 robertbu · Mar 15, 2013 at 05:07 AM 0
Share

Not sure what you are after. To find everything after above you can do something like:

 f = f * 100.0f;
 f -= $$anonymous$$athf.Floor(f);
 f = f / 100.0f;
avatar image flamy · Mar 15, 2013 at 05:17 AM 0
Share

the question is not clear.. can you explain clearly want you want with a example set of numbers or something?

avatar image sdgd · Mar 15, 2013 at 05:28 AM 0
Share

because it's not exactly randome

because most of times you get too much or too less that's why I'd do it on timer and set it from range

0.009 - 0.05 for true 0.05-0.1 for false

or what ever I want to do with % and numbers

1 Reply

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

Answer by Tarlius · Mar 15, 2013 at 05:08 AM

You could use % (modulo) or Mathf.Floor(). Note that % is a division operation, so be sure to check the second argument is not 0.

There might be a better way depending on what the end result you want is though. Why is random bad?

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 sdgd · Mar 15, 2013 at 05:31 AM 0
Share

oh ok I can see that $$anonymous$$athf.Floor is doing same job as I'm

I don't like randome because it many times gives too large or some times too low

let say if I give it 50% chance

some times it'll rapidly give 75-85%

and some times it'll rapidly give 15-25%

you just can't get it around 45-55%

and even if you go on huge amounts like 10$$anonymous$$ you won't always get around 50% but more like 40-60 or even wider range

I don't like that

so giving time 0.01 is accuretly enough so noone is actually able to precise hit the button on correct time and the % accurecy is much better

avatar image sparkzbarca · Mar 15, 2013 at 06:10 AM 1
Share

basically what you want is for past results to influence future performance so as to normalize the chance. Ok well just code it in.....

do a SuccessionCount bool LastValue;

guess a random number and see if it fails or succeeds

if fail last value = false;

if true last value = true

also if fail & lastvalue = false; successioncount++ else succesioncount = 0;

same for true

so that tracks each time you get a value the same as the last one

and lets you know how mnay tiems in a row you've done the same thing.

you can now use succession count inside your algorithm of probability.

for eaxmple

probably = 50 + 10 * succession count

now for a result to happen 3 times there is a 50% chance teh first time a 40% chacne of it happening agian and only a 30% chance if it's happened twice. that helps prevent chains of success or failure.

avatar image Tarlius · Mar 15, 2013 at 07:39 AM 0
Share

A random number will "tend towards" 50% but, as you say, it can be uneven for small samples. It really depends on what you are trying to achieve. I think its probably worth noting that your time-based approach would be subject to the same randomness, by the way. In fact, random number generators sometimes take time as one of the inputs for calculating the "random" number.

If you start tracking frequencies, if you are not careful about the implementation its possible you might fluctuate even more as well. If you do use something like Sparkzbarka suggested, be sure to Clamp the values so you don't even up with negative probabilities/etc.

Imagine this situation: Game is an RPG with critical hits and dodges, which are "balanced" with a bias that makes one more likely as the other occurs. User gets "lucky" and dodges 4 times in a row. To "balance" the outcomes, the game forces 4 criticals in a row. Suddenly dodge goes from a useful stat to a dangerous stat! (I realise this is pretty extreme, but trying to make the point)

Another thing you might want to look into is binomial distributions of random numbers (basically adding 2 random numbers together). That will give you a very strong bias towards the centre. (Add two random numbers between 0-1 and you are much more likely to get around 1 than 0 or 2)

avatar image sparkzbarca · Mar 15, 2013 at 07:35 PM 0
Share

yea my method would never punish you though per say. That is if you did good things it would only increase the chance you wouldnt do it again. The moment you break the cycle the probability resets.

It's not like 50 to 60 to 70 to 80 percent then to 70 to 60

its 50,60,70,80 fail 50

and of course crits and dodge would each have there own seperate non interactable counters.

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

13 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

Related Questions

Distribute terrain in zones 3 Answers

Raycasting how to find position on end of ray float distance 1 Answer

how to find no file exists? 2 Answers

Multiple Cars not working 1 Answer

how to send data from client to client? 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