fork download
  1. using UnityEngine;
  2. using System.Linq;
  3.  
  4. public class NewBehaviourScript4 : MonoBehaviour
  5. {
  6. void Start()
  7. {
  8. int i = Random.Range(0, 3);
  9.  
  10. switch (i)
  11. {
  12. case 0://平均的
  13. forRandom();
  14. break;
  15. case 1://そこそこ荒れる
  16. forifRandom();
  17. break;
  18. case 2://けっこう荒れる
  19. whileRandom();
  20. break;
  21. }
  22. }
  23. //平均的なランダム数値
  24. void forRandom()
  25. {
  26. int StartMaxStatus = 300;
  27. int[] status = new int[10];
  28. for (int i = 0; i < StartMaxStatus; i++)
  29. {
  30. int j = Random.Range(0, status.Length);
  31. status[j]++;
  32. }
  33. }
  34. //けっこう荒れるランダム数値
  35. void whileRandom()
  36. {
  37. int StartMaxStatus = 300;
  38. int[] status = new int[10];
  39. while (status.Sum() < StartMaxStatus)
  40. {
  41. int j = Random.Range(0, status.Length);
  42. status[j] += Random.Range(-20, 20 + 1);
  43. if (status[j] < 1)
  44. {
  45. //forced restore under 0
  46. status[j] = 1;
  47. }
  48. }
  49. while (status.Sum() > StartMaxStatus)
  50. {
  51. int j = Random.Range(0, status.Length);
  52. if (status[j] > 1)
  53. {
  54. //not need 0
  55. status[j]--;
  56. }
  57. }
  58. }
  59. //そこそこ荒れるランダム数値
  60. void forifRandom()
  61. {
  62. int point = 300;
  63. int[] num = new int[10];
  64.  
  65. for (int i = 0; i < 10; i++)
  66. {
  67. if (i == 9)
  68. num[i] = point;
  69. else if (point == 0)
  70. num[i] = 0;
  71. else
  72. {
  73. int tmpPoint = Random.Range(0, 61);
  74. if (tmpPoint < point)
  75. {
  76. num[i] = tmpPoint;
  77. point -= tmpPoint;
  78. }
  79. else
  80. {
  81. num[i] = tmpPoint;
  82. point = 0;
  83. }
  84. }
  85. }
  86. }
  87. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(1,7): error CS0246: The type or namespace name `UnityEngine' could not be found. Are you missing an assembly reference?
prog.cs(4,36): error CS0246: The type or namespace name `MonoBehaviour' could not be found. Are you missing an assembly reference?
Compilation failed: 2 error(s), 0 warnings
stdout
Standard output is empty